0

Working with Flash Builder 4.5 I have implemented a custom preloader by extending SparkDownloadProgressBar. Now I want the preloader to stay on the screen until my Application has loaded in external data. Once the Application external data has loaded, I want to have the preloader dispatch the Event.COMPLETE event.

The intent is to have a 3 phase preloader. 1st load the RSLs, 2nd the SWF, 3rd application will load the data.

I've overridden the initCompleteHandler function so it does not fire the Event.COMPLETE event once the swf is loaded. I have a public function in the preloader called removePreloader which fires the Event.COMPLETE event.

There is a property in the Application named preloader but it's null.

How can my application call the preloader?

Thanks, Gary

Gary
  • 145
  • 1
  • 2
  • 15
  • I found an answer but StackOverflow wont let me post it for 8 hours. The short of it is I set a variable in the Application to a preloader function. The application can then call that function when it's ready. Once StackOverflow let me post the code, I will. – Gary Oct 26 '11 at 19:47

1 Answers1

0

I'm not sure if this is the most elegant AS3 solution but it is working. If you have a better method, please post.

In the application mxml, I added the following variable:

public var preloaderFinalFireFunction:Function;

In the preloader (which extends SparkDownloadProgressBar) I override the initCompleteHandler to assign a function that's inside the preloader to the application. When i'm ready for the preloader to be removed, the application calls preloaderFinalFireFunction();

override protected function initCompleteHandler(event:Event):void{
  var app:MyApplication = MyApplication(FlexGlobals.topLevelApplication);
  app.preloaderFinalFireFunction = removePreloader;
}

protected function removePreloader():void{
  var app:MyApplication = MyApplication(FlexGlobals.topLevelApplication);
  app.preloaderFinalFireFunction = null;
  dispatchEvent(new Event(Event.COMPLETE));
}
Gary
  • 145
  • 1
  • 2
  • 15