2 Replies Latest reply on Sep 9, 2008 11:38 PM by jixlee

    how to implement module preloader

    jixlee
      i know application has preloader property,user can custom himself preloader,but i need to custom module preloader,pls help me
        • 1. Re: how to implement module preloader
          atta707 Level 2
          You can use events of the ModuleLoader class to implement your own progress bar indicating the progress. Take a look at the topic "Using ModuleLoader events" in the Flex Builder help.

          <?xml version="1.0" encoding="iso-8859-1"?>
          <!-- modules/CustomModuleLoader.mxml -->
          <mx:ModuleLoader xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          public function init():void {
          addEventListener("urlChanged", onUrlChanged);
          addEventListener("loading", onLoading);
          addEventListener("progress", onProgress);
          addEventListener("setup", onSetup);
          addEventListener("ready", onReady);
          addEventListener("error", onError);
          addEventListener("unload", onUnload);

          standin = panel;
          removeChild(standin);
          }

          public function onUrlChanged(event:Event):void {
          if (url == null) {
          if (contains(standin))
          removeChild(standin);
          } else {
          if (!contains(standin))
          addChild(standin);
          }
          progress.indeterminate=true;
          unload.enabled=false;
          reload.enabled=false;
          }

          public function onLoading(event:Event):void {
          progress.label="Loading module " + url;
          if (!contains(standin))
          addChild(standin);

          progress.indeterminate=true;
          unload.enabled=false;
          reload.enabled=false;
          }

          public function onProgress(event:Event):void {
          progress.label="Loaded %1 of %2 bytes...";
          progress.indeterminate=false;
          unload.enabled=true;
          reload.enabled=false;
          }

          public function onSetup(event:Event):void {
          progress.label="Module " + url + " initialized!";
          progress.indeterminate=false;
          unload.enabled=true;
          reload.enabled=true;
          }

          public function onReady(event:Event):void {
          progress.label="Module " + url + " successfully loaded!";
          unload.enabled=true;
          reload.enabled=true;

          if (contains(standin))
          removeChild(standin);
          }

          public function onError(event:Event):void {
          progress.label="Error loading module " + url;
          unload.enabled=false;
          reload.enabled=true;
          }

          public function onUnload(event:Event):void {
          if (url == null) {
          if (contains(standin))
          removeChild(standin);
          } else {
          if (!contains(standin))
          addChild(standin);
          }
          progress.indeterminate=true;
          progress.label="Module " + url + " was unloaded!";
          unload.enabled=false;
          reload.enabled=true;
          }

          public var standin:DisplayObject;
          ]]>
          </mx:Script>

          <mx:Panel id="panel" width="100%">
          <mx:ProgressBar width="100%" id="progress" source="{this}"/>
          <mx:HBox width="100%">
          <mx:Button id="unload"
          label="Unload Module"
          click="unloadModule()"
          />
          <mx:Button id="reload"
          label="Reload Module"
          click="unloadModule();loadModule()"
          />
          </mx:HBox>
          </mx:Panel>
          </mx:ModuleLoader>


          Main application:

          <?xml version="1.0"?>
          • 2. Re: how to implement module preloader
            jixlee Level 1
            thanks for your reply,i mean,there are somethings in my module,i wanna use my load dynamic resource instead of progress bar,for example i need load many images dynamiclly in my module,user see appearance until loaded finished.during load image,i need appear load image progress info on the stage
            how should i implement