6 Replies Latest reply on Dec 9, 2009 10:41 AM by Flex harUI

    Unloading Modules with ModuleManager

    Gregory Lafrance Level 6

      I load a module using ModuleManager.

       

      info is an instance of IModuleInfo.

       

      The following returns a DisplayObject which I successfully add to a VBox in the ModuleEvent.READY event handler:

      info.factory.create()

       

      But before I add it I remove the first child from the VBox. It will only contain one child, the current module.

       

       

           private function modLoadHandler(e:ModuleEvent):void {
              if(moduleVB.numChildren > 0){
                var disObj:DisplayObject = moduleVB.removeChildAt(0);
              }
              moduleVB.addChild(DisplayObject(info.factory.create() as moduleType));
            }


      My question is whether or not this is how to unload a module before loading a different module.

       

      IModuleInfo objects have an unload method, and you can assign a ModuleEvent.UNLOAD event handler, bu t it seems if you do that the IModuleInfo you use to call factory.create() is invalid, perhaps only when you try to reload a module that was loaded then unloaded.

       

      So my basic question is how to properly unload modules when using ModuleManager (I don't want to use ModuleLoader).

       

      Example code will be much appreciated.

        • 1. Re: Unloading Modules with ModuleManager
          aktell2007

           

          Hi there,

           

          I’m not sure if this is help to you but I give it a try!

           

          My apps are working only on modules and I found this code once written by a FLEX guru, but unfortunately I can’t remember his web site or his name; tried often but just can’t find it any longer.

          Anyway, this code was part of an example he supplied and I have used it ever since. It is very much simpler than yours but maybe it helps.

           

           

          After Importing the relevant items and using the public var info:IModuleInfo; I init the ModuleLoader.getModule – url – info.load

           

           

                         <mx:Script>

                            <![CDATA[

           

                                  public function createModule(m:ModuleLoader, s:String):void {

           

                                        if (!m.url) {

                                        m.url = s;

                                        return;

                                        }

                                        m.loadModule();

                                  }

                                 

                                        public function removeModule(m:ModuleLoader):void {

                                              m.unloadModule();

                                        }

                            ]]>

                         </mx:Script>

           

           

          Also preloadModules in a similar way. Now I use all my stuff in a ViewStack

           

           

          <mx:ViewStack selectedIndex="{currentStep}"

                                  width="100%" height="100%">

                                 

                                  <mx:VBox

                                        width="100%" height="100%"

                                              verticalScrollPolicy="off"

                                              horizontalScrollPolicy="off">                                    

                                  <mx:ModuleLoader url="com/modIntro/StepIntroGeneral.swf"

                                        id="stepIntro"/>

                                  </mx:VBox>

          etc.

           

           

          Addressing: currentStep in a Button:

           

          click="currentStep = 0, createModule(stepIntro, l1.text, removeModule.Step1, removeModule.Step2 etc.)"

           

          If there is anything for you to work with please let me know and I will supply the full code but have to find the section for unloading for you first!

           

          thanks aktell2007

          • 2. Re: Unloading Modules with ModuleManager
            Gregory Lafrance Level 6

            Yeah, using ModuleLoader is easier than using ModuleManager. I often like to take the more difficult route, because that is where the power is.

             

            But if you see any code showing the "best practice" for how to unload using ModuleManager, I'll appreciate your passing it my way.

            • 3. Re: Unloading Modules with ModuleManager
              aktell2007 Level 1

              Hi again,

               

              Have you ever seen a .pdf file from ADOBE which only was addressing issues with modules of both Module Loader and Module Manager. I do have it in my large library of books and Pdf's. I would only have to find it if you need it because I just overhauled my computer systems and have orginized everything new on to different external disks.

               

              regards aktell2007

              • 4. Re: Unloading Modules with ModuleManager
                Darrell Loverin Level 4

                I recommend you use the ModuleLoader.as source as a best practice for using ModuleManager.

                 

                 

                 

                -Darrell

                • 5. Re: Unloading Modules with ModuleManager
                  Gregory Lafrance Level 6

                  I appreciate your suggestion, but I'm curious why using ModuleLoader is preferable over ModuleManger.

                   

                  I understand that in simpler cases it would be preferable, but I'm assuming that using ModuleManager might have advantages in some circumstances.

                   

                  I'd appreciate any insight on this.

                   

                  Still, what is the best practice for unloading modules using ModuleManager, particularly in situations where the user might select one module, so it loads, select another, so the first one unloads, and that first one might be loaded again later.

                  • 6. Re: Unloading Modules with ModuleManager
                    Flex harUI Adobe Employee

                    Darrell is just suggesting that you look at the code in ModuleLoader, you don't need to use it.

                     

                    You can also try using the release() method.

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

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