Resources: ActionScript 3
ActionScript 3 Preloader
21 May 2011
Copy and paste this code into the first frame of your AS3 Flash document to create a preloader.
Note: Remember you will need to target the right movieclips in order for the percentage bar to display!
// HALT!
stop();
/* =========================== PRELOADER === */
/* ========================================= */
stage.addEventListener(Event.ENTER_FRAME, loading)
// EVERY FRAME
function loading(evt){
// CALCULATE PERCENTAGE
var loaded = stage.loaderInfo.bytesLoaded;
var total = stage.loaderInfo.bytesTotal;
var loadProgress = loaded / total;
var loadProgressPercent = Math.round(loadProgress * 100);
// CREATE DISPLAY
mcLoader.mcLoaderBar.width = loadProgressPercent;
// IF 100% SEND TO MAIN ANIMATION
if (loadProgress == 1){
gotoAndPlay('PLAY');
stage.removeEventListener(Event.ENTER_FRAME, loading);
}
}