AIR 常用技巧

1.air打开关联类型文件

如果该应用程序是由于文件类型关联而被调用,则文件的完整路径将包含在命令行参数中。

应用程序可通过以下方法处理 invoke 事件:即向其 NativeApplication 对象注册侦听器,
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent); 
air.NativeApplication.nativeApplication.addEventListener(air.InvokeEvent.INVOKE, onInvokeEvent);
详见:
<a target=_blank href="http://help.adobe.com/zh_CN/AIR/1.1/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5d46-8000.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e1a" target="_blank">http://help.adobe.com/zh_CN/AIR/1.1/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5d46-8000.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e1a</a>

详见:
<a target=_blank href="http://help.adobe.com/zh_CN/AIR/1.1/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5d46-8000.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e1a" target="_blank">http://help.adobe.com/zh_CN/AIR/1.1/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5d46-8000.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e1a</a>

2.air 打开系统文件目录

var file:File = new File(directoryPath);
file.openWithDefaultApplication();

3.AIR NativeProcess 调用bat

<span style="white-space: pre;"><span style="font-family:Arial, Helvetica, sans-serif;"><span style="background-color: rgb(255, 255, 255);">	</span></span>NativeProcess在windows下只能调用exe</span>, 所以,直接把.bat的路径传入nativeProcess的参数中肯定不行。解决方案是用NativeProcess调用cmd.exe,然后将bat的路径以参数传入cmd.exe。这样就可以通过cmd来执行bat了。

<span style="white-space:pre">	</span><span style="font-weight: normal;">var batFile:File = new File();
        NativeApplication.nativeApplication.autoExit = true;
        batFile = batFile.resolvePath("C:/Windows/System32/cmd.exe");
        var batPath:String = File.applicationDirectory.nativePath + "\\mybat.bat";
        var process:NativeProcess = new NativeProcess();
        var processArg:Vector.<String> = new Vector.<String>();
        processArg[0] = "/c";/加上/c,是cmd的参数
        processArg[1] = batPath;
        processArg[2] = "%1";//参数1,传入cmd内
        var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        info.executable = batFile;
        info.arguments = processArg;
        process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
        process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, outputHandlers);
        process.start(info);</span></span>

4.调用browsfor文件或文件夹时,默认定位到剪贴板位置

<span style="font-weight: normal;"><span style="white-space:pre">	</span>var msg:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;
        var f:File = new File();
        try {
            f.nativePath = msg;
        } catch (evt:ArgumentError) {
            trace("参数不合法");
        }</span>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章