2009-10-12 2 views
4

안녕하세요, 아주 간단한 mxml 예제입니다. 모듈이 원격 http://edofiles.s3.amazonaws.com/calculator.swf 준비 이벤트가 발생되지 않습니다플렉스로드 모듈 READY 이벤트가 시작되지 않았습니다. 이유가 무엇입니까?

같은 경우

플렉스 SDK 3.4.0와 플렉스 빌더를 사용하여, 나는 그 이유를 이해하지 않습니다.

동일한 문제가 발생합니까?

원래 코드는 http://lowpitch.com/blog/modulemanager-and-imoduleinfo-loading-flex-modules-dynamically/#comment-4396

모든 단서가에서입니까?

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    applicationComplete="initApp()"> 
    <mx:Script> 
     <![CDATA[ 
      import mx.modules.Module; 
      import mx.events.ModuleEvent; 
      import mx.modules.ModuleManager; 
      import mx.modules.IModuleInfo; 

      protected var _moduleInfo:IModuleInfo; 

      private function initApp():void { 
       addToLog ("Application initialised"); 
       // create the module - note, we're not loading it yet 
       _moduleInfo = ModuleManager.getModule("http://edofiles.s3.amazonaws.com/calculator.swf"); 
       // add some listeners 
       _moduleInfo.addEventListener(ModuleEvent.READY, onModuleReady); 
       _moduleInfo.addEventListener(ModuleEvent.SETUP, onModuleSetup); 
       _moduleInfo.addEventListener(ModuleEvent.UNLOAD, onModuleUnload); 
       _moduleInfo.addEventListener(ModuleEvent.PROGRESS, onModuleProgress); 
      } 

      protected function getModuleInfo() : IModuleInfo { 
       // return the module info 
       return _moduleInfo; 
      } 

      /** 
      * Adds output to the log 
      **/ 
      protected function addToLog (msg:String) : void { 
       log.text += msg + "\n"; 
       // scroll to the bottom on the next frame 
       callLater(scrollToBottom); 

      } 

      protected function scrollToBottom() : void { 
       // scroll to the bottom 
       log.verticalScrollPosition = log.maxVerticalScrollPosition; 
      } 

      /** 
      * Called when the "load" button is pressed 
      * 
      * Starts loading the module - when the module has been 
      * loaded, an instance of the module will be created 
      * and added to the tile control 
      * 
      **/ 
      private function loadModule() : void { 
       addToLog ("Loading module"); 
       // load the module 
       getModuleInfo().load(); 
      } 

      /** 
      * Called when the "unload" button is pressed 
      * 
      * Removes all the instances of the module from the 
      * tile control, then unloads the module 
      * 
      */ 
      private function unloadModule() : void { 
       addToLog ("Unloading module"); 
       // clear out all the the instances 
       // of the module from the tile 
       tile.removeAllChildren(); 
       // unload the module 
       getModuleInfo().release(); 
       //getModuleInfo().un 
      } 

      /** 
      * Handler for the ModuleEvent.PROGRESS event 
      **/ 
      protected function onModuleProgress (e:ModuleEvent) : void { 
       addToLog ("ModuleEvent.PROGRESS received: " + e.bytesLoaded + " of " + e.bytesTotal + " loaded."); 
      } 

      /** 
      * Handler for the ModuleEvent.SETUP event 
      **/ 
      private function onModuleSetup (e:ModuleEvent) : void { 
       addToLog ("ModuleEvent.SETUP received"); 
       // cast the currentTarget 
       var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo; 
       addToLog ("Calling IModuleInfo.factory.info()"); 
       // grab the info and display information about it 
       var info:Object = moduleInfo.factory.info(); 
       for (var each:String in info) { 
        addToLog ("  " + each + " = " + info[each]); 
       } 

      } 

      /** 
      * Handler for the ModuleEvent.READY event 
      **/ 
      private function onModuleReady (e:ModuleEvent):void { 
       addToLog ("ModuleEvent.READY received"); 
       // cast the currentTarget 
       var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo; 
       // Add an instance of the module's class to the 
       // display list. 
       addToLog ("Calling IModuleInfo.factory.create()"); 
       tile.addChild(moduleInfo.factory.create() as Module); 
       addToLog ("SomeModule instance created and added to Display List"); 
      } 

      /** 
      * Handler for the ModuleEvent.UNLOAD event 
      **/ 
      public function onModuleUnload (e:ModuleEvent) : void { 
       addToLog ("ModuleEvent.UNLOAD received"); 
      } 

     ]]> 
    </mx:Script> 

    <mx:HBox width="100%" height="100%"> 
     <mx:Tile id="tile" width="100%" height="100%" /> 
      <mx:TextArea id="log" width="100%" height="100%"/> 
    </mx:HBox> 


    <mx:ApplicationControlBar> 
     <mx:Button label="Load" click="loadModule()" /> 
     <mx:Button label="Unload" click="unloadModule()"/> 
    </mx:ApplicationControlBar> 

</mx:Application> 
+0

null 정보에 addEventListener를 시도해 볼 수 있습니다. –

답변

0

이유는 간단하고 재미있을 수 있습니다. try try : 처음 addEventListener 코드, 다음 getModule().

3

오늘이 행동이있었습니다. 비록 그것이 포스터가 요구 한 것과 직접적인 관련이 없지만,이 주제는 Google 검색에서 상당히 높아지기 때문에, 나는 여기서 비틀 거린 다른 사람들을 돕고 싶습니다. http://www.joshuaostrom.com/2008/08/14/flex-modules-watch-your-scope/

문제는 당신이 load()를 호출 할 때 ModuleLoader 자동 쓰레기 수집하는, 그래서 당신은 당신의 참조가 조심하지 않으면, 당신의 청취자가 파괴받을 수 있습니다

나는 다음 블로그에서 해결책을 발견했다.

0

디버그 용으로 컴파일 된 응용 프로그램과 함께 릴리스 용으로 컴파일 된 모듈을로드하려고 시도하기 때문에 발생할 수도 있습니다. 이것은 전에 나에게 일어났다. 앱과 모듈 모두 디버그/디버그 또는 릴리스/릴리스와 일치해야합니다.

일치하지 않으면 진행 이벤트와 "설정"이벤트는 표시되지만 준비 이벤트는 표시되지 않습니다.

관련 문제