Tony Alves
Flex, .Net, and Fluorine

Flex Preloader Example

Tuesday, 31 July 2007 16:37 by talves
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 ) );
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

October 6. 2008 08:03