You want to be able to write your custom preloader in FLEX?

Jesse Warden will be able to walk you through it here.

Before you leave to go write your new preloader, make sure to read my comment on needing to remove the event listeners when you are done.

Summary:
Awesome stuff! There is a caveat to consider.

1. The preloader overwrites the event Listeners, but leaves them once the application is loaded. This is ok if you never load anything else into your flex application. If you load a module into your application, flex will fire the FlexEvent.INIT_PROGRESS event again causing an error due to the clip.preloader becoming null.

2. Solution:
Instantiate a private variable called _preloader in your constructor;

private var _preloader:Sprite;
public override function set preloader(preloader:Sprite):void
{
_preloader = preloader;
_preloader.addEventListener( ProgressEvent.PROGRESS , onSWFDownloadProgress );
_preloader.addEventListener( Event.COMPLETE , onSWFDownloadComplete );
_preloader.addEventListener( FlexEvent.INIT_PROGRESS , onFlexInitProgress );
_preloader.addEventListener( FlexEvent.INIT_COMPLETE , onFlexInitComplete );
centerPreloader();
}


Remove the listeners once the application is loaded and you are complete;

private function onDoneAnimating():void
{
clip.stop();
_preloader.removeEventListener( ProgressEvent.PROGRESS , onSWFDownloadProgress );
_preloader.removeEventListener( Event.COMPLETE , onSWFDownloadComplete };
_preloader.removeEventListener( FlexEvent.INIT_PROGRESS , onFlexInitProgress );
_preloader.removeEventListener( FlexEvent.INIT_COMPLETE , onFlexInitComplete );
dispatchEvent( new Event( Event.COMPLETE ) );
}

Currently rated 2.7 by 6 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5