- Home
- Tutorials
- Flash
- Intermediate
- Preloading Multiple Loaded Movies

Multi-preloader code
Now let's examine the script. First the Mainf.fla, Frame 1.
stop ();
loadMovieNum ("phase1.swf", 1);
This script states:
- Stop playing
- Load the phase1.swf movie clip up on Level1.
Note that this script is the same for all the other frames, except we load a different number phase into a different level.
Now we need to look at the source of phase1.fla, so open it up. You will see it has it's own little preloader in the first 2 frames:
Frame 1:
total_bytes = _root.getBytesTotal();
loaded_bytes = _root.getBytesLoaded();
percent_done = int((loaded_bytes/total_bytes)*100);
ifFrameLoaded ("Scene 2", 1) {
stop ();
_level0.nextFrame();
}
Ignore the first 3 lines of this, they are simply my percentage loaded calculator from the Percentage Preloader tutorial. Line 4 is the standard preloader test to check if our last desired frame is loaded. In this case, it checks if Scene 2, Frame 1, in the phase1.swf clip is loaded. If so, it performs the actions within the curly brackets. Here's the trick: normally you would have a gotoAndPlay() action within those curly brackets to start your movie going now that it's preloaded, but we don't want to start it yet because the other's aren't loaded, so I've inserted a stop() instance. I've also added a Tell target goto command ( _level0.nextFrame(); ) , using the Flash 5 syntax, which sends our main.swf file to the next frame. Note that this is a gotoAndStop command, (nextFrame() is not a play command), as a gotoAndPlay command would cause debugging errors.
Frame 2:
gotoAndPlay (1);
Frame 2 loops back to Frame 1 until Frame 1 indicates the movie is completely loaded.
So now our first clip is loaded and our main movie has been moved forward one frame. Can you guess what's in the 2nd frame of our main movie? That's right, a command to load the second loadable clip. Once this one is loaded, it will send our main movie to Frame 3 ... I'm sure you've got the hang of the cycle by now. This is also why you should have one frame per loaded clip plus one additional frame at the end. This additional end frame provides a target for the _level0.nextFrame(); command of the final loaded clip.
