从浏览器启动Air应用程序

时间:2010-07-06 20:30:51

标签: flex flash air

我正致力于将空中应用程序与Web应用程序集成,并且大多数情况下都能正常运行。

我遇到的唯一问题是,当我尝试从启动徽章传递变量时,应用程序无法加载,我的swf没有错误。

这是我目前的代码库:

启动徽章AS:

package {
import flash.display.*;
import flash.events.*;
import flash.geom.ColorTransform;
import flash.net.URLRequest;
import flash.system.*;
import flash.text.TextField;

// AIRBadge is our main document class
public class LaunchApplication extends MovieClip {

    public function LaunchApplication() {

        _loader = new Loader();
        var loaderContext:LoaderContext = new LoaderContext();
        loaderContext.applicationDomain = ApplicationDomain.currentDomain;

        _loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
        _loader.load(new URLRequest(BROWSERAPI_URL_BASE + "/air.swf"), loaderContext);

        var parameters:Object = LoaderInfo(this.root.loaderInfo).parameters;
        _applicationID = parameters["applicationID"];
        _arguments = String(parameters["arguments"]).split(",");

    }

    private function onInit(e:Event):void {
        _air = e.target.content;
        switch (_air.getStatus()) {
            case "installed" :
                statusMessage.text = "AIR is installed and has been detected."
                launchButton.addEventListener(MouseEvent.CLICK,onButtonClicked);
                break;
            case "available" :
                // AIR is Available
                statusMessage.text = "AIR is not installed - application cannot be launched."
                break;
            case "unavailable" :
                // AIR Not Available
                statusMessage.text = "AIR is not installed - application cannot be launched."
                break;
        }
    }

    private function onButtonClicked(e:Event):void {

        statusMessage.text = "Attempting to Launch AIR Application";
        trace(_applicationID);
        _air.launchApplication(_applicationID,_arguments);

    }

    private const BROWSERAPI_URL_BASE: String = "http://airdownload.adobe.com/air/browserapi";

    private var _applicationID:String;
    private var _arguments: Array;

    private var _loader:Loader;
    private var _air:Object;

}

}

使用Javascript:

<script type="text/javascript">
var so = new SWFObject("launchMovie.swf", "badge", "250", "75", "9.0.115", "#FFFFFF");
so.addVariable( "applicationID", "com.testapp.test");
so.addVariable( "arguments", "123");
so.write("flashcontent");
</script>

2 个答案:

答案 0 :(得分:0)

您是否检查过AIR项目中的* -app.xml文件并设置为true?

答案 1 :(得分:0)

http://www.knomedia.com/air/badgeBuilder/检查此工具。它非常酷且易于创建AIR徽章。