Posts RSS Comments RSS 38 Posts and 67 Comments till now

All about preloader - Part III: Preloader in AS2

The most important information for a preloader is the number of bytes loaded and the total number of bytes of the file (file size). In ActionScript 2, getBytesLoaded and getBytesTotal functions serve the purpose. The most basic implementation is like this:

stop();
function preload() {
	var l:Number = getBytesLoaded();// loaded bytes of the swf file
	var t:Number = getBytesTotal();// total bytes of the swf file
	var p:Number = l/t;// percentage loaded of the swf file, value range from 0-1
	updatePreloader(l,t,p);
	if (p == 1) {
		onEnterFrame = null;// remove onEnterFrame loop
		gotoAndStop("main");// go to the main frame
	}
}
function updatePreloader(l:Number,t:Number,p:Number){
	//most of the time l and t are not used, but just in case you need it there's no harm to keep them
	trace("bytesLoaded: "+l+"  bytesTotal: "+t+"  percentage: "+p);
}
onEnterFrame = preload;

Based on Part II’s 2 keyframes structure, the codes above should be placed in the “preloader” key frame and core codes should be placed in “main” key frame.

Visuals for indicating the loading progress can be easily extended from the basic codes shown above. All we need to do is to play around with updatePreloader function. Here’s a list of simple visuals:

Simple Text

Simpy Bar

Simple Text with Simple Bar

Simple Animation

Simple ActionScript

In Part II, we talked about using bandwidth profiler to prepare files. Here, we’ll need to use a tool called Simulate Download to test a preloader. In Flash IDE testing mode (Ctrl/Apple+Enter), you can choose to simulate download from View->Simulate Download or press Ctrl/Apple + Enter again. The Download Settings menu has default options for various internet speed and it also allows customisation.

Trackback this post | Feed on Comments to this post

Leave a Reply

For spam filtering purposes, please copy the number 2890 to the field below: