8 Replies Latest reply on Jul 28, 2009 5:50 AM by vpxav

    ModuleLoader, "ready" event not working

    vpxav

      Hello,

      I have a problem, if I use this code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initM1()">
          <mx:Script>
               <![CDATA[
                   import mx.controls.Label;
                   public var myVar:myModule;    
                  private function initM1():void{
                      myVar = m1.child as myModule;
                      myVar.label1.text="data sent!";
                  }
               ]]>
          </mx:Script>
          <mx:Panel width="100%">
              <mx:ModuleLoader id="m1" url="myModule.swf" ready="initM1()"/>
          </mx:Panel>   
      </mx:Application>

      the function is not called (I cannot see the module's label1.text changed).

       

      But if I do this:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
               <![CDATA[
                   import mx.controls.Label;
                   private var myVar:myModule;    
                  private function initM1():void{
                      myVar = m1.child as myModule;
                      myVar.label1.text="data sent!";
                  }
               ]]>
          </mx:Script>
          <mx:Panel width="100%">
              <mx:ModuleLoader id="m1" url="myModule.swf" />
              <mx:Button click="initM1();"/>
          </mx:Panel>
      </mx:Application>

      the function is called when the button is clicked.

       

      Why isn't it working with the "ready" event of my ModuleLoader?

      How to correct this?

       

      Thank you for you help.

        • 1. Re: ModuleLoader, "ready" event not working
          rgadiparthi Level 2

          try

           

          <mx:ModuleLoader id="m1" url="view.swf" setup="initM1(event)"/>

          • 2. Re: ModuleLoader, "ready" event not working
            Gus187 Level 1

            You may try adding listeners to the error, progress, setup events and see if any of these can give you more information about why is not calling the ready event.

             

            HTH Gus

            • 3. Re: ModuleLoader, "ready" event not working
              Gaurav J Adobe Employee

              event handler for ready event expects an event of type ModuleEvent.

               

              Have you tried:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" >
                  <mx:Script>
                       <![CDATA[
                           import mx.controls.Label;

              import mx.events.MoudleEvent;
                           public var myVar:myModule;    
                          private function initM1(e:ModuleEvent):void{
                              myVar = m1.child as myModule;
                              myVar.label1.text="data sent!";
                          }
                       ]]>
                  </mx:Script>
                  <mx:Panel width="100%">
                      <mx:ModuleLoader id="m1" url="myModule.swf" ready="initM1(event)"/>
                  </mx:Panel>   
              </mx:Application>

               

              Thanks,

              Gaurav Jain

              Flex SDK Team

              http://www.gauravj.com/blog

              • 4. Re: ModuleLoader, "ready" event not working
                vpxav Level 1

                Hello,

                sorry for the late reply... I was on holiday.

                I thank you very much for your help but the previous tip did not work. Of course, I replaced

                import mx.events.MoudleEvent;

                with

                import mx.events.ModuleEvent;

                 

                Might it be because I'm using flex with Eclipse on Linux?

                Thank you.

                • 5. Re: ModuleLoader, "ready" event not working
                  Flex harUI Adobe Employee

                  Are you trying this on a debug player?  I would expect an error.  The child objects of the moduleLoader.child are probably not available when your READY handler is called

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui

                  1 person found this helpful
                  • 6. Re: ModuleLoader, "ready" event not working
                    vpxav Level 1

                    Hello,

                    I have indeed an error in the debugger;

                    don't know what to do with this error:

                    [SWF] /TESTS/TESTS.swf - 586,250 bytes after decompression
                    [SWF] /TESTS/myModule.swf - 59,200 bytes after decompression
                    TypeError: Error #1009: Cannot access a property or method of a null object reference.
                        at TESTS/initM1()[/home/xavier/workspace/TESTS/src/TESTS.mxml:10]
                        at TESTS/__m1_ready()[/home/xavier/workspace/TESTS/src/TESTS.mxml:15]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\co re\UIComponent.as:9051]
                        at mx.modules::ModuleLoader/moduleReadyHandler()[E:\dev\3.0.x\frameworks\projects\framework\ src\mx\modules\ModuleLoader.as:335]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at ModuleInfoProxy/moduleEventHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\mo dules\ModuleManager.as:1027]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at ModuleInfo/readyHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\modules\Modul eManager.as:706]
                        at flash.events::EventDispatcher/dispatchEventFunction()
                        at flash.events::EventDispatcher/dispatchEvent()
                        at mx.core::FlexModuleFactory/update()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\cor e\FlexModuleFactory.as:325]
                        at mx.core::FlexModuleFactory/docFrameHandler()[E:\dev\3.0.x\frameworks\projects\framework\s rc\mx\core\FlexModuleFactory.as:413]

                    Any idea?

                    • 7. Re: ModuleLoader, "ready" event not working
                      Flex harUI Adobe Employee

                      Like I said, the children of the child are not available when the READY event dispatches.  I would use the READY event to hook up a CREATION_COMPLETE handler and call initM1() then.

                       

                      Alex Harui

                      Flex SDK Developer

                      Adobe Systems Inc.

                      Blog: http://blogs.adobe.com/aharui

                      • 8. Re: ModuleLoader, "ready" event not working
                        vpxav Level 1

                        Hello, I'm really sorry but I don't understand what I have to do...

                        Here are the two little files I'm using to do this test.

                         

                        Could anyone modify it so that it works. It will be much easier for me to understand.

                        There are only a few lines.

                         

                        Thank you very much.