Preloader Code and Tutorial by David Bricker

//specify a percent of the movie to preload
//don't use a "%" sign
percentToLoad = 100;
//set the following to be either "percent" or "k"
//to determine the type of information to be displayed
displayPercent = false;
//determine total bytes in the movie with getBytesTotal()
//divide getBytesTotal()by 1000 to get K (1K = 1000bytes)

kTotal = _parent.getBytesTotal()/ 1000;
//determine total K to preload by factoring in the percentToLoad
//round off the decimal point using Math.round()
//be sure to divide percentToLoad by 100 to get the actual percentage

preloadTotal = Math.round(kTotal * (percentToLoad/100));
this.onEnterFrame = function() {//start the loop
getKLoaded();//call a function that gets the amount Loaded
if (Math.round(KLoaded) < Math.round(KTotal)) {//if the whole movie is not loaded yet
calcPercentLoaded();//call a function to calculate percent Loaded
scaleProgressBar();//call a function to scale the bar
updateDisplay();//call a function to update the display
} else {//otherwise, if the whole movie has loaded
delete this.onEnterFrame;//stop the enterFrame loop
_parent.play();//play the movie Clip's parent
}
}
calcPercentLoaded = function() {
kLoaded = Math.round(_parent.getBytesLoaded()/1000);
percentLoaded = Math.round((kLoaded/preLoadTotal)*100);
}
scaleProgressBar = function() {
bar_mc._xscale = percentLoaded;
}
updateDisplay = function() {
if (displayPercent == true) {
progress_txt.text = percentLoaded + "% LOADED";
} else {
progress_txt.text = kLoaded + "K OF " + preloadTotal+ "K LOADED";
}
}

top

This tutorial was written by Dave Bricker of Spot Grafix, Inc. and taken from Wildform's Flash Website.

close window ~