Search This Blog

Tuesday, April 10, 2007

Flex Preloader

package myComponents
{
import mx.preloaders.*;
import flash.events.ProgressEvent;

public class DownloadProgressBarSubClassMin extends DownloadProgressBar
{
public function DownloadProgressBarSubClassMin()
{
super();
// Set the download label.
downloadingLabel="Downloading app..."
// Set the initialization label.
initializingLabel="Initializing app..."
// Set the minimum display time to 2 seconds.
MINIMUM_DISPLAY_TIME=2000;
}

// Override to return true so progress bar appears
// during initialization.
override protected function showDisplayForInit(elapsedTime:int,
count:int):Boolean {
return true;
}

// Override to return true so progress bar appears during download.
override protected function showDisplayForDownloading(
elapsedTime:int, event:ProgressEvent):Boolean {
return true;
}
}

}

You can use your custom class in a Flex application, as the following example shows:


mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
preloader="myComponents.DownloadProgressBarSubClassMin">

mx:Application>

CSS Style Example for Preloader:

ProgressBar {
borderColor: #cc0066;
barColor: #000000;
trackColors: #009999, #99ffcc;
color: #000000;
paddingLeft: 7;
paddingRight: 11;
textIndent: 14;
trackHeight: 21;
verticalGap: 20;
}

2 comments:

Anonymous said...

The style doesnt seem to work. Any idea why?

Gautam said...

The DownloadProgressBar has a protected method: createChildren(). It doesn't use the StyleManager during the download and initilization phase. Hence you need to override this method if you have to implement your own style.

The DownloadProgressBar class displays download progress. It is used by the Preloader control to provide user feedback while the application is downloading and loading. The download progress bar displays information about two different phases of the application: the download phase and the initialization phase. Do not implement a download progress bar as an MXML component because it loads too slowly.