Home > Learn Flash > Flash AS3 Preloader Tutorial

Flash AS3 Preloader Tutorial


This is a tutorial on how to make a very simple AS3 (CS4) preloader for your Flash movies. This tutorial assumes you are a beginner at Flash.

 preloader

1) Create a new flash document and a draw rectangle on the stage. This will be our preloader bar.

2) Select it, then click Modify in the top menu and then Convert to symbol

3) Give it any name you like and make sure that the Type is selected to Movie Clip. Also make sure you select the middle left box on the registration point as we want it to expand from left to right. Click OK to save.

 symbolconvertclick to enlarge

4) Underneath the preloader bar you just drew, insert a dynamic text field.

5) Give the preloader bar an instance name of “loaderBar” and give the text field an instance name of “loaderText”

 loaderbarinstancename

 textinsatncename

6) Make a new layer above the current one and label it “actionscript”. You can also give the bottom layer a name such as “bar” if you want.

 actionscriptlayer

Click on the first frame of the actionscript layer and open the actions window. (Click Window and then Actions in the top menu)

7) Insert the following code:

stop();
import flash.display.*;
this.stop();
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PRELOADER);
function PRELOADER(event:ProgressEvent):void {
var percent:Number=event.bytesLoaded/event.bytesTotal*100;
loaderBar.scaleX=pcent/100;
loaderText.text=int(percent)+”%”;
if(percent==100){
this.gotoAndStop(2);
}
}

8) Make a new blank frame at frame two of the layer with the preloader bar you drew and import a picture so we have something to load.

9) Click Control and then Test Movie and… it won’t work properly. As you are loading this file from your computer, it will load instantaneously. We need to slow down the load rate for us to check it works.

10) Click on View in the top menu and then Simulate download. You should now see your preloader bar slowly expand with the progress in a percentage underneath. If you are still having problems you can adjust the download simulation rate in View and then Download settings

 flashiconDownload the example file here

NOTES

If you have an animation that plays from frame 2 onwards you can change the line “this.gotoAndStop(2);” to “this.gotoAndPlay(2);”

Please leave your questions, comments and responses to this article. Please let me know of any mistakes, inaccuracies or problems with this tutorial and I’ll try to fix it. Enjoy!


Post to Twitter Post to Facebook Post to StumbleUpon

  1. jeff topping
    December 9th, 2009 at 21:15 | #1

    hi,
    im trying your preloader tutorial. I have a movie i just made and im sticking a preloader in front of it. your preloader bar is only in frame 1 of its own layer. So where does the rest of my movie go? can i add it to the layers below this preloader or do i need to make all my layers into it’s own movie and then add it on frame 2 of the preloader?

    thanks
    jeff

  2. September 22nd, 2010 at 03:27 | #2

    i’m having a lot of trouble doing this, being bought up with cobol on the mainframe, tis type of language i can’t get. how can i put a preloaded on the website above?

  3. admin
    September 22nd, 2010 at 03:38 | #3

    Not quite sure I understand the question. Could you be a little more specific?

  4. September 22nd, 2010 at 09:24 | #4

    ok, if you look at my web site, it doesn’t load fast, i need a preloader. i tried to follow you code but i just dont understand where to put the code for the preload. do i have a new scene ore a different swf file which i import and call.

  5. September 23rd, 2010 at 09:25 | #5

    if you look at my web site, http://www.cyberweb.com.au, it doesn’t load fast, i need a preloader. i tried to follow your code but i just dont understand where to put the code for the preload. do i have a new scene ore a different swf file which i import and call.

  6. ceecee
    September 17th, 2011 at 03:37 | #6

    hi, i tried the first time to make a preloader. i found a lot of codes and tuts, but only yours worked… just one thing i cannot solve. when i load my site in IE8 and want to refresh it, only the full bar shows and nothing happens. in FF and safari it works fine… got a clue what i can do??

    best regards
    ceecee

  1. No trackbacks yet.