Preloader
For every PageLoader its possible to specify a PreloaderPage which will be shown while the PageLoader is loading the external assets specified in the Page. Every PreloaderModule in the PreloaderPage will receive the progress event of the loading queue for all the assets.
To setup the PageLoader with a Preloader you add a PreloaderPage subnode to the PageLoader as the following example shows (keep in mind that the ModularApplication is also a PageLoader):
<ModularApplication> <Page> <!-- your default page with assets and modules --> </Page> <PreloaderPage> <Assets> <Library path="prelaoderLibrary.swf" /> </Assets> <Modules> <Module class="modules.MyPreloader" /> </Modules> </PreloaderPage> </ModularApplication>
To receive the progress event of the loading our PreloaderModule in the example the MyPreloader class we must extend from the modular.core.module.PreloaderModule. Let have a look on the source of the MyPreloader class:
package modules {
import modular.core.event.AssetsProgressEvent;
import modular.core.module.PreloaderModule;
public class MyPreloader extends PreloaderModule {
public function MyPreloader() {
super();
}
public override function onProgress(pe:AssetsProgressEvent):void {
trace( pe.entireProgress ); // traces a number between 0 (nothing loaded) and 1 (everything loaded )
trace( pe.currentProgressEvent ); // traces the current active progressevent. keep in mind, that you can have multiple assets.
trace( pe.currentTarget ); // traces the current asset loader
}
}
}
As you can see you simply have to override the function onProgress to get information of the current active download and the entire download progress.
As the PreloaderPage is just a normal page you can use any number and kind of modules in your preloaderpage as long as they are stored in the preloader library. But only modules that extend from the PreloaderModule get the progress event.
Keep your library where you store the preloader modules as small as possible because this will be loaded before anything is displayed.
modular searches for classes also in the preloader page so you can reuse modules from the preloader page also in you main page.
Comments