Happy TutorialsThis 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....
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 |
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% |
|
On the stage, give each object these instance names |
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!
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() {
} |
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.
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. |
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