
Now that the movie is operational and is uploaded to my blog I found one thing missing to finish it off... A loading bar. I noticed whenever I look at it online, it takes some time to load and during this process a blank screen is the main center of attention. To add some professionalism to the work I began looking into creating a loading bar, which was easier said then done! As this Flash movie was created using action script 3 (which is the latest version), there's not allot of help out there on the world wide web for aspiring beginners such as myself. I found plenty of tutorials explaining how to do it using AS2, but as I'm not easily beaten I plodded on looking at forums and trying out different peoples ideas. Eventually I found this little beauty.
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
/*This is the main function, basically it grabs the total and loaded bytes, calculates a percentage, and displays it by stretching the bar and adjusting the textfield display. If your bar/textbox instance names are NOT lbar/lpc, you'll need to adjust this code to match your instance names*/
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
//Stretch the bar
lbar.scaleX=pcent/100;
//Display the % loaded in textfield
lpc.text=int(pcent)+"%";
//If the movie is fully loaded, kick to the next frame on the main timeline
//You may wish to change the gotoAndStop(2) to a gotoAndPlay(2)
if(pcent==100){
this.gotoAndStop(2);
}
}
No comments:
Post a Comment