5 Replies Latest reply on Jul 24, 2009 7:52 PM by mdanrel

    ModuleLoader child object is null

    mdanrel

      Hi folks,

       

      I'm trying to understand where I might be going wrong.  My application consists of a main app which upon login loads one of three

      possible modules, based on the user role. I've chosen to use the Module Loader approach to keep the main app size down.

       

      I've looked at several pieces of sample code and followed the example in Flex 3 documentation, but that code isn't working and I'm at a

      loss to explain why.  The main application uses a ModuleLoader and a module interface so that I can pass data to the child module that

      I want loaded.

       

      When the READY event is received, a function is called to then set some data via the interface, and this seems to work fine. However,

      the module loader child is null and so nothing happens - I get the debug message "child property is null".  Any ideas on what may be going wrong ?

       

      This code is verbatim from the Flex help documentation.

       

       

           [Bindable (event="eventLoginSucceeded")]

           private function doSuccess( e:LoginEvent ):void {

                customLoader.url = "modules/module1.swf";

           }



           private function applyModuleSettings( e:Event):void{

       


           var ichild:* = customLoader.child as IModuleInterface;

       

          

           if ( customLoader.child != null ) {

       

                ichild.setLibraryCollection( globalCollection );

           }

           else

                {

                     trace ( "customLoader.child property is null ");

                }

           }

      ...

      <l:myModuleLoader id="customLoader" ready="applyModuleSettings(event)"/>
      Any help would be appreciated.

        • 1. Re: ModuleLoader child object is null
          Flex harUI Adobe Employee

          Is customLoader.child null?  Maybe it just isn't an IModuleInterface?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

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

          • 2. Re: ModuleLoader child object is null
            mdanrel Level 1

            Yes, the child is null.  I followed the examples straight out of the Adobe online help. 

             

            Main application uses a module loader, the IModuleInterface is an interface I created to the module to be loaded.

             

            when I examine the customloader object in the Debug watch window, it's child property is indeed null.  Yet the console shows the

            module loading ( I see the number of bytes loaded > 1MB ).

            • 3. Re: ModuleLoader child object is null
              Flex harUI Adobe Employee

              ModuleLoader.child can also be null if the main class in the module is not a DisplayObject.  To load non-DisplayObjects, using ModuleManager.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

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

              • 4. Re: ModuleLoader child object is null
                mdanrel Level 1

                The module is a display object, so I think that it should be OK.  Just to be sure I created a very simplistic test app and even tried

                it without the interface.  Still get the same result

                 

                <mx:Application >

                     <mx:Script>

                          <![CDATA[

                 

                    

                          private function go( ):void{

                               myModuleLoader.url = "modules/module2.swf";

                               trace ( myModuleLoader.child );

                          }

                 

                          ]]>


                     </mx:Script>

                 

                     <mx:Button x="52" y="96" label="Load the Module" click="go();"/>

                 

                     <mx:ModuleLoader id="myModuleLoader" />

                </mx:Application>

                 

                the module code is just a grid object, but in the real application it would be a form with tabs, and other display objects.

                 

                <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">

                     <mx:DataGrid x="49" y="43">

                               <mx:columns>

                                    <mx:DataGridColumn headerText="Column 1" dataField="col1"/>

                               </mx:columns>

                     </mx:DataGrid>

                 

                 

                </mx:Module>

                 

                 

                The module loads just fine, but the child property is still null.  What am I missing?

                • 5. Re: ModuleLoader child object is null
                  mdanrel Level 1

                  I did a little more tinkering with the test app.  My last code sample had an error in it -- forgot to add an event handler for the Module READY event. 

                  So my trace statement wasn't placed in the right spot.  Sorry for the oversight.

                   

                  So my test app seemed to work fine, and I even modified it to use the module interface and it seemed to work. 

                   

                  So I went back to my original app.

                   

                  Everything was the same, and I looked into this DisplayObject thing. 

                   

                  My module loads a custom view, but it is not inside a container.   So I put a wrapper around it   <mx:Canvas> which is the same size as the container and all looks good now.

                   

                   

                   

                  So this problem seems to be solved for now.  Thanks for your help Alex.