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:
Continue Reading »
Shang :: May.06.2008 ::
beginner ::
No Comments »