ActionScript 3.0 Video Lesson 27: Creating a Pre Loader

Sun, Sep 6, 2009

ActionScript

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 req:URLRequest = new URLRequest(“Clock.swf”);
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);

Related Articles:

, , , , , , , , , , , , , , , , , , , , ,

5 Responses to “ActionScript 3.0 Video Lesson 27: Creating a Pre Loader”

  1. TutorialsRoom Says:

    Nice tutorial, It was added to the homepage of http://www.tutorialsroom.com

    Keep on the good work :)

  2. Thomas Says:

    Very good tutorial overall, it really helped me.. even as a total flash newbie i got how to make this preload bar.

    Although:
    Newcommers need to notice 2 things;
    1. if copying the code from above, all “” qoutemarkes are faulty.. theyre like this: “ยดยด instead of “” this will make the code unable to work and say syntax error
    2. A problem i’m still trying to solve: Once its done loading, it still shows the “Progress text” it does not disapear.

    - Thomas

  3. Thomas Says:

    Edit:
    To fix the problem with the loading text not disapearing again after load.
    Change your function

    function fileLoaded(event:Event):void{
    addChild(loader);
    }

    to:

    fileLoaded(event:Event):void{
    preload_txt.text = “”;
    addChild(loader);
    }

    Hope this will help people in the future :) .. else really good job mate, hope you’ll do more awesome tutorials

  4. Abe Says:

    you are right about the quotes. It happens on copy and paste from Flash.

  5. Abe Says:

    the code is tested, should work the way it is.


Leave a Reply

Security Code:

AVA Trading Forex
WIX create a FREE website.
Try ACT! 2010 Today
Accept Credit Cards
UseNeXT Fast Downloads
For Free Stuff Click Here

Get Paid for Filling Surveys


Go Daddy $7.49.com sale 125x125 Huddle Collaboration
oDesk Certified Action Script Programmer oDesk Certified Adobe Flash CS3 Designer oDesk Certified Adobe Photoshop 6.0 Designer

Compare Web Hosting Services and Prices

web hosting - Web Hosting guide to popular hosts.

Twitter Followers