加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AIR 常用技巧

发布时间:2020-12-15 20:07:45 所属栏目:百科 来源:网络整理
导读:1.air打开关联类型文件 如果该应用程序是由于文件类型关联而被调用,则文件的完整路径将包含在命令行参数中。 应用程序可通过以下方法处理 invoke 事件:即向其 NativeApplication 对象注册侦听器, NativeApplication.nativeApplication.addEventListener(I

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,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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读