AIR Browser调用没有获取参数

时间:2012-05-17 02:19:06

标签: actionscript-3 flash flex air flex3

我终于想出了如何从浏览器启动我的AIR本机安装程序桌面应用程序,但我没有收到任何传入的参数。

我将此添加到我的原生安装程序应用程序(来自http://livedocs.adobe.com/flex/3/html/help.html?content=app_launch_1.html

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"       
       invoke="onInvoke(event)">
<mx:Script>
<![CDATA[
import flash.events.InvokeEvent;
import flash.desktop.NativeApplication;

public function onInvoke(invokeEvent:InvokeEvent):void {
    var now:String = new Date().toTimeString();
    logEvent("Invoke event received: " + now);

    if (invokeEvent.currentDirectory != null){
        logEvent("Current directory=" + invokeEvent.currentDirectory.nativePath);
    } else {
        logEvent("--no directory information available--");
    }

    if (invokeEvent.arguments.length > 0){
        logEvent("Arguments: " + invokeEvent.arguments.toString());
    } else {
        logEvent("--no arguments--");
    }
}

public function logEvent(entry:String):void {
    log.text += entry + "\n";
    trace(entry);
}
]]>

(etc.)

该应用程序已成功从此方法启动

        private function onButtonClicked(e:Event):void {
            var APP_ID:String = "my_app";
            var PUB_ID:String = "";
            var ARGS:Array = ["123", "abc"];
            _air.launchApplication( APP_ID,PUB_ID, ARGS );
        }

logEvent表示收到了Invoke事件,但我总是得到“--no arguments--”。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

在申请时使用BrowserInvokeEvent代替invokeEvent

在您的应用程序完整处理程序

中添加它
NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE, onBrowserInvoke);

然后在浏览器启动时传递参数的下方方法。

protected function onBrowserInvoke(event:BrowserInvokeEvent):void
{
    Alert.show(event.arguments.toString(),"My Args");           
}