com.bumpslide.util.TimelinePreloader
Preloads a timeline and dispatches events along the way We like to have a delay before we show a loading indicator, so we wait for the EVENT_SHOW_INDICATOR event before showing the load indicator. By default, this delay is set to 1 second. Once that delay is passed, you will notice that the EVENT_PRELOAD_PROGRESS event contains a property called 'adjustedPercent'. This is a percentage of remaining bytes offset by the amount loaded before the 1 second delay. You can choose to use this percentage to feed your load indicator if you want a bar that doesn't start at 50% or something similar. You can hide the progress bar and start your app reliably once the EVENT_PRELOAD_COMPLETE event is received.
Example Usage:
var display_txt:TextField; var preloader:TimelinePreloader; function init() { stop(); display_txt.autoSize = true; display_txt._visible = false; preloader = new TimelinePreloader( this ); preloader.addEventListener( TimelinePreloader.EVENT_SHOW_INDICATOR, Delegate.create( this, showProgressBar ) ); preloader.addEventListener( TimelinePreloader.EVENT_PRELOAD_PROGRESS, Delegate.create( this, updateProgressBar ) ); preloader.addEventListener( TimelinePreloader.EVENT_PRELOAD_COMPLETE, Delegate.create( this, hideProgressBarAndStartApp ) ); preloader.start(); } function showProgressBar() { display_txt._visible = true; } function updateProgressBar(e:Object) { var pct:String = Math.round( e.adjustedPercent*100 ) + "%"; display_txt.text = "Loaded "+pct; } function hideProgressBarAndStartApp() { gotoAndStop("start"); } init();You can remove or alter the indicator delay time with code such as:
preloader.indicatorDelayTime = 0;
static public EVENT_SHOW_INDICATOR:Stringstatic public EVENT_PRELOAD_PROGRESS:Stringstatic public EVENT_PRELOAD_COMPLETE:StringindicatorDelayTime:Number [Write Only]addEventListener:FunctionremoveEventListener:FunctiondispatchEvent:FunctiondispatchQueue:Function