Flash builder basic - 尝试加载air.swf文件

时间:2011-08-24 09:19:29

标签: air flash mxml flash-builder

我创建了一个新的Flex项目,并在.mxml文件中包含以下代码。

<?xml version="1.0"?>
<!-- usingas/StatementSyntax.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="doSomething()">
    <mx:Script><![CDATA[
        var airSWF:Object; // This will be the reference to the main class of air.swf
        var airSWFLoader:Loader = new Loader(); // Used to load the SWF
        var loaderContext:LoaderContext = new LoaderContext(); 
        // Used to set the application domain domain

        loaderContext.applicationDomain = ApplicationDomain.currentDomain;

        airSWFLoader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
        airSWFLoader.load(new URLRequest("http://airdownload.adobe.com/air/browserapi/air.swf"), 
            loaderContext);

        function onInit(e:Event):void 
        {
            airSWF = e.target.content;
        }
    ]]></mx:Script>

    <mx:Label id="label1"/>

</mx:Application>

这些是错误:

1120:访问未定义的属性airSWFLoader。 WebTry.mxml / WebTry / src第12行Flex问题

1120:访问未定义的属性loaderContext。 WebTry.mxml / WebTry / src第10行Flex问题

我们的想法是能够让air.swf文件在上面的代码中运行,以检测我们的航空应用程序是否已安装,从浏览器启动航空应用程序等。

1 个答案:

答案 0 :(得分:0)

好吧,没有人回答,但这是解决方案!

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                           creationComplete="init()" >

        <fx:Script>
                <![CDATA[

                        public function init():void {
                                _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);
                        }

                        private function onInit(e:Event):void {
                                _air = e.target.content;
                                launchButton.enabled = true;
                        }

                        private function onButtonClicked(e:Event):void {
                                **_air.launchApplication( APP_ID,PUB_ID, ANY_ARGS) );**
                        }

                        private const BROWSERAPI_URL_BASE: String = "http://airdownload.adobe.com/air/browserapi";
                        private var _loader:Loader;
                        private var _air:Object;
                ]]>
        </fx:Script>


        <s:Button id="launchButton" x="10" y="175" label="Launch Application"
                          click="onButtonClicked(event)" enabled="false"/>

</s:Application>

请更换**

之间的项目