Preloaders in AS3

Here are a few way to create a preloader in flash actionscript 3

One way is to set two event listeners on the statge for PROGRESS and COMPLETE.

import flash.display.*;
stop();
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, preloaderFunc);
function preloaderFunc (event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
preloader_mc.txt.text=int(pcent)+"%";
}
this.loaderInfo.addEventListener (Event.COMPLETE, playFrame);
function playFrame (e:Event):void {
play ();
}

A second method would be to use the Enter Frame event like the onEnterFrame for as2.

addEventListener(Event.ENTER_FRAME, preloader);
function preloader(event:Event) :void {
	var bytestotal = stage.loaderInfo.bytesTotal;
	var bytesloaded = stage.loaderInfo.bytesLoaded;
	var pctLoaded:int = bytesloaded * 100 / bytestotal;
	preloader_mc.txt.text = String(pctLoaded) + "%";
	if (bytesloaded >= bytestotal) {
		removeEventListener(Event.ENTER_FRAME, preloader);
		play();
	}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »