A preloader is often used on large Flash files that may take a while to download i.e. those containing lots of bitmap graphics, video clips, sounds, or lots of keyframes. It gives the user some indication of how the download is progressing – which is more reassuring to users than a blank screen.
The preloader is usually a short animation or some other kind of indicator of the progress of the download of the Flash file.
The information presented here shows you how to create a ‘progress bar’ – a rectangular bar of colour that grows in length as the Flash movie downloads. It should be straightforward to amend this to show the download progress as a percentage or some other metric.
stop();
// creates a timer that runs the preloader function every 10ms
myInterval=setInterval(preloader,10);
// defines a function called preloader
function preloader(){
// checks if all the frames are loaded or not
if (_framesloaded < _totalframes){
// scales the progress bar as a percentage of frames loaded
_root.progressbar._xscale=(_framesloaded/_totalframes)*100;
} else {
// plays the main movie and clears the timer
play();
clearInterval(myInterval);
}
}
Note: for flash files that don’t have a lot of frames to load, the number of bytes loaded could be used instead.
To obtain the total number of bytes (size) of a Flash file use the following:
tbytes=getBytesTotal();
bloaded=getBytesLoaded();
In the example code, replace _framesloaded with bloaded, and replace _totalframes with tbytes