Flash Download Progress Bar Tutorial

This is a simple way of loading in another SWF movie, or image, and having a loader progress bar showing the user how long they have to wait....

Step 1. What objects make up download progress bar

Show This Step

A scrolling window is made up of simply 2 items:

1. A movieclip inwhich the other file will be loaded into

2. A movieclip for the progress bar that grows to show how much is downloaded

3. The grey object behind

Hide This Step

Step 2. Creating the objects

Show This Step

Create these two objects, they are both simple movieclips. It doesn't matter what size of colour they are, but make sure they are scaled to 100%

scale 100%

On the stage, give each object these instance names

Click here to download this file.

Hide This Step

Step 3. Loading a SWF movie

Show This Step

We now need to add some code to load in a SWF file. For this example I'm loading a large SWF off this website 'http://www.happytutorials.com/flash/progressbar/polarbear.swf' It's a large file, about 1meg

Frame 1 Code Human Person Language

mcHolder.loadMovie("http://www.happytutorials.com/flash/progressbar/polarbear.swf")

the name of the moveicip . load a movie ( this movie! )

It's pretty simple!

Click here to download this file.

Hide This Step

Step 4. Making the progress bar show how much is loaded

Show This Step

Now, on FRAME 2 we need to make add some code that makes the progress bar grow, and show how much of the file is loaded.

Below the loadMovie function, add this code

FRAME 2 Code Human Person Language

stop()

 

this.onEnterFrame = function() {

 

loaded = mcHolder.getBytesLoaded();

total = mcHolder.getBytesTotal();

percentageLoaded = 100 / total * loaded;

mcProgressBar._xscale = percentageLoaded

if (percentageLoaded >= 100) { gotoAndStop(3) }

 

}

even though we're staying on 1 frame this, makes everying between the {} repeat continuous at the same speed as the movies frame rate

 

get how much has been loaded

look how big the file is

work out the percentage loaded

adjust the xscale of the loader bar

if it's 100% loaded, remove this enterframe function - it basically removes all this code and stops worrying about it!

FRAME 3 Code Human Person Language

stop()

 

that'll do for code, you can add some graphics saying 'Loaded', or remove the loaded bar off frame 3 if you want

The key is _xscale of the bar. If 10% of the clip is loaded, the bar appears 10% it's original size, it 80% is loaded, it's 80% it's size, and when it's all loaded, the bar shows up at it's full original size.

Click here to download this file.

Note

Once flash has download loaded the file, it keeps it in memory, so thereafter your progress bar won't really be effective becuase the file is already 100% downloaded. For testing purposes you can do this:

Frame 1 Code Human Person Language

mcHolder.loadMovie("http://www.happytutorials.com/flash/progressbar/polarbear.swf?id=123")

adding id=xxx to the end, and changing it each time you test the move, flash thinks the file is a different file, and downloads it each time you change the number.

Hide This Step

Comments?

To make the ideal, most useful tutorials, I need your comments. Did you understand everything, did I make any mistakes, or not explain something? Did it simply not work! Let me know