2011-08-24 57 views
0

我創建了一個新的Flex項目,並在.mxml文件中包含以下代碼。Flash builder basic - 嘗試加載air.swf文件

<?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 line 12 Flex問題

1120:訪問未定義的屬性loaderContext。 WebTry.mxml/WebTry/src line 10 Flex問題

這個想法是爲了能夠得到在上面的代碼中工作的air.swf文件來檢測我們的應用程序是否安裝,從瀏覽器啓動無線應用程序,等等。

回答

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> 

請更換**

之間的項目