What do we do when we want to make sure that our clip only start after all items are downloaded. A Flash Pre Loader, written in ActionScript 3.0, that show the download percentage, makes sure all items are in place before our movie starts.
HERE IS THE SOURCE CODE
var loader:Loader = new Loader();
/* It may sound funny but loader
with small “L” is not a reserved word
therefore available for a variable name,
while Loader with Capital “L” is
a reserved word and becomes blue */
function fileLoaded(event:Event):void{
addChild(loader);
}
function preload(event:ProgressEvent):void {
var percent:Number = Math.round(event.bytesLoaded / event.bytesTotal *100);
/* both values are received on the function
through the Progress event */
// Dynamic text boxes accept only strings, so the value has to be transformed into string, using the string function.
preload_txt.text = String(percent) + “%”;
}
/* Now the code */
// This function fires when the Loading is Completed
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
// This function happens during loading.
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preload);
loader.load(req);



































September 8th, 2009 at 11:43 am
Nice tutorial, It was added to the homepage of http://www.tutorialsroom.com
Keep on the good work