2 Replies Latest reply on Jun 29, 2009 5:04 AM by Benoitcn

    How to load modules using  Flex4 sdk?

    Benoitcn Level 1

      How to load modules using moduleManager?

        • 1. Re: How to load modules using  Flex4 sdk?
          Gregory Lafrance Level 6

          This link should help:

           

          http://livedocs.adobe.com/flex/3/html/help.html?content=modular_5.html

           

          See the section entitled: "Using the ModuleManager class to load modules"

           

           

          If this post answers your question or helps, please mark it as such.

           

           

          <?xml version="1.0"?>
          <!-- modules/ModuleLoaderApp.mxml -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
              <mx:Script>
                  <![CDATA[
                  import mx.events.ModuleEvent;
                  import mx.modules.ModuleManager;
                  import mx.modules.IModuleInfo;
          
                  public var info:IModuleInfo;
                  
                  private function initApp():void {
                      info = ModuleManager.getModule("ColumnChartModule.swf");
                      info.addEventListener(ModuleEvent.READY, modEventHandler);           
          
                      // Load the module into memory. Calling load() makes the
                      // IFlexModuleFactory available. You can then get an
                      // instance of the class using the factory's create()
                      // method.
                      info.load();
                  }
                  
                  private function modEventHandler(e:ModuleEvent):void {
                      // Add an instance of the module's class to the
                      // display list.
                      vb1.addChild(info.factory.create() as ColumnChartModule);
                  }
                  ]]>
              </mx:Script>
          
              <mx:VBox id="vb1"/>
          
          </mx:Application>
          
          
          • 2. Re: How to load modules using  Flex4 sdk?
            Benoitcn Level 1
            If I declare a moduleloader object in mxml it works.
            <mx:ModuleLoader url="modules/workalert_mod.swf"
                  id="AllStaffLoader" width="100%" height="292"
                  x="0" y="475"  x.workAlert="1" y.workAlert="478"/>
            But I want to dynamically load a module, so I try to do this using modulemanager.
            private var WorkAlert:Class;
            protected function application_initializeHandler():void
              {
              module = ModuleManager.getModule("modules/workalert_mod.swf");
            /* the event never dispatch, Why ? */
            /* I can't do angthing, because there is no error at runtime at all */
              module.addEventListener(ModuleEvent.READY, moduleReadyHandler);
              module.load();
              }
            /* it doesn't run actually*/
              private function moduleReadyHandler(e:ModuleEvent):void{
              switch(module.url){
                case "module/workalert_mod.swf":
                AllStaffLoader.removeAllChildren();
                AllStaffLoader.addChild(module.factory.create() as DisplayObject);
                break;
              }
              }