4 Replies Latest reply on May 14, 2009 3:23 PM by M. Regert

    Problem with module loading another module

    M. Regert Level 1

      I have run into what appears to be a bug in Adobe Flex 3.3, but would like others opinion.  I have a simple application which loads a module.

      If a user checks a box, then the module loads a submodule and calls a funtion in that submodule which modifies the UI slightly.

       

      It really is simple code, but not easy to explain, so bear with me on this :-)  All code is attached.  Rename from *.txt to *.mxml.

       

      I have added an event listener to the submodule loader for the ModuleEvent.READY event so that I can call a function in it once it is loaded (the function modifies the UI):

       

       

       

       

       

       

       

       

      private function onModuleReady(event:Event):void

      {

           Alert.show(

      "Module load successful", "Success");

       

       

           if (loader2.child is SubModule) {

       

       

                var module:SubModule = loader2.child as SubModule;

                module.createCompleteHandler();

                module.modifyUI(pnlMain);

           }

      else {

                Alert.show(

      "loader is NOT SubModule", "Failure");

           }

      }

       

       

       

      Stepping through the debugger, loader2.child IS INDEED a SubModule Class, yet I consistantly step into the else clause.  As I debugged this, I added a similar event listener for the READY even on the loading of the first module.  By just defining a new function in the main module, this code now works.  I don't have to actually call that function, just define it, meaning that if I comment out the entire function onModuleReady (the one defined in the main application that is just printing out a trace), I get the error stated above.

       

       

       

       

       

       

       

       

       

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="createCompleteHandler()"

      >

       

       

      <mx:Script>

      <![CDATA[

       

       

      import

      MainModule;

       

       

      import

      mx.events.ModuleEvent;

       

       

      private function createCompleteHandler():void

      {

      loader.url =

       

      "MainModule.swf"

      ;

      // loader.addEventListener(ModuleEvent.READY, onModuleReady);

      loader.loadModule();

      }

       

       

       

      private function onModuleReady(event:Event):void

      {

       

       

      if (loader.child is

      MainModule) {

       

       

      trace("here"

      );

      }

      }

       

      Please try the attached code, and try running it with the function onModuleReady implelented in the Application body and with it removed.  Why would defining a function that is never called for the first module affect the second module?