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>