Bookmark and Share

Here is the simple code for AS3 preloader, slightly different from AS2:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
this.addEventListener(Event.ENTER_FRAME, loadProgress);
 
function loadProgress(event:Event):void {
	var bytes_loaded:int = this.root.loaderInfo.bytesLoaded;
	var bytes_total:int = this.root.loaderInfo.bytesTotal;
	var bytes_percent:int = Math.round((bytes_loaded/bytes_total)*100);
	trace(bytes_percent + "% is loaded");
	if (bytes_loaded >= bytes_total) {
		trace("This movie is loaded");
		removeEventListener(Event.ENTER_FRAME, loadProgress);
	}
};