Wednesday, May 14, 2008

Preloader

Complex Flash applications on the Web normally have preloaders. These are short animations that display the load status (by bar graph or percent) of required data for the demo.

Some Flash Websites provide tutorials on how to create preloaders using the timeline. This is only available in Adobe Flash (developer studio). I have never seen an Open Source solution. I created a sample preloader class that can be called prior to drawing the main screen.

Add a new ActionScript Class in the oas2 subfolder called Preloader. Copy and paste this code. Save changes.

Open Application.as and delete all code. Copy and paste this code.

In the previous version, the text, rectangle, and rotating star were placed in the constructor. This code has been moved to a private function called init(). This routine is only called after the preloader is complete.

Save the file (Application.as), and the SWF file is automatically rebuilt by Eclipse. Click to see a preloader in the Flash demo. When finished loading, the rotating star appears.

The Preloader class has been built with a special mode to simulate real world loading. Normally, SWF files are loaded instantly from a local disk. Use the static function Preloader.enable_download_simulator to enable this mode.

No comments: