2 Replies Latest reply on Apr 7, 2010 9:49 AM by saisri2k2

    Help on loading modules

    saisri2k2 Level 4



      I've problem with module loading. Currently in my application we load all the modules at the start of the application. so any part of the application if needs a modules it will call using the following method currently


      var oModule:IModule = mainApp.getModule('name');




      so, the main app has the references to all the modules which are loaded at the start of the application.. but now, we are trying to make the module loading dynamic - load on demand.


      So, the mainApp has to load the module which is asked by the app and give the reference back to the oModule(above example) after loading the module. In mean time i would like to show loading page(with flash 'loading' displayed). How do i achieve this?



        • 1. Re: Help on loading modules
          Karl_Sigiscar_1971 Level 3

          Using a dependency injection framework like Parsley and the Cairngorm 3 module library will help you a lot. You will be able to inject into each module the dependencies (object instances) it needs without having the shell app referencing the module (hence the inversion of control).


          Here's what I have implemented to show a loading animation for each module (loaderprocessmc is a Flex component created from Flash CS3 that has animation frames ranging from 1 to 100; it has a nested movieclip called animation):


          In each module mxml:






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


          <preloaders:DownloadProgressBar xmlns:preloaders="mx.preloaders.*"


                  import flash.events.Event;
                  import flash.events.ProgressEvent;


                  import mx.events.*;
                  import mx.preloaders.Preloader;
                  import mx.preloaders.DownloadProgressBar;
                  import mx.core.Application;


                  private var loader:loaderprocessmc;    


                  override public function set preloader( preloader:Sprite ):void
                      preloader.addEventListener( ProgressEvent.PROGRESS , SWFDownloadProgress );
                      preloader.addEventListener( Event.COMPLETE , SWFDownloadComplete );
                      preloader.addEventListener( FlexEvent.INIT_PROGRESS , FlexInitProgress );
                      preloader.addEventListener( FlexEvent.INIT_COMPLETE , FlexInitComplete );


                      loader = new loaderprocessmc();
                      loader.x = stageWidth  / 2 - (loader.width / 2);
                      loader.y = stageHeight / 2 - (loader.height / 2);
                  private function SWFDownloadProgress( event:ProgressEvent ):void
                      var percent:uint = (event.bytesLoaded / event.bytesTotal) * 100;
                  private function SWFDownloadComplete( event:Event ):void {}
                  private function FlexInitProgress( event:Event ):void {}
                  private function FlexInitComplete( event:Event ):void
                      dispatchEvent( new Event( Event.COMPLETE ) );

          1 person found this helpful
          • 2. Re: Help on loading modules
            saisri2k2 Level 4

            Thanks for the reply.. i would try it !!