2009-10-12 7 views
4

Bonjour, J'ai cet exemple mxml très simple.Modules de chargement flexibles L'événement READY n'est pas déclenché, pourquoi?

flex avec l'aide du Générateur sdk flex 3.4.0 si le module est à distance comme http://edofiles.s3.amazonaws.com/calculator.swf

L'événement READY est jamais tiré, je ne comprends pas pourquoi.

Avez-vous le même comportement?

code original est de http://lowpitch.com/blog/modulemanager-and-imoduleinfo-loading-flex-modules-dynamically/#comment-4396

Des indices?

<?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

vous pouvez essayer addEventListener sur null info, voir ce qu'il se passe –

Répondre

0

La raison peut être simple et amusante. Essayez taht: premier code addEventListener, next getModule().

3

J'ai eu ce comportement aujourd'hui. Même si ce n'est pas directement lié à ce que l'affiche a demandé, ce sujet arrive assez haut dans la recherche google, donc je veux aider les autres qui trébuchent ici.

J'ai trouvé la solution sur le blog suivant: http://www.joshuaostrom.com/2008/08/14/flex-modules-watch-your-scope/

Le problème est que les ordures automatiquement ModuleLoader recueille lorsque vous appelez load(), donc si vous n'êtes pas très prudent avec vos références, vos auditeurs peuvent se détruire.

0

Cela peut aussi arriver parce que vous essayez de charger un module compilé pour la publication avec une application compilée pour le débogage. ça m'est déja arrivé. L'application et les modules doivent correspondre à la mise au point/au débogage ou à la libération/publication. Si elles ne correspondent pas, vous obtiendrez des événements de progression et des événements de "configuration", mais jamais un événement prêt.

Questions connexes