Tutorial details:
Written by: Jesse Stratford
Time: 10 - 20 minutes
Difficulty Level: Intermediate
Requirements: Flash 4 or higher
Topics Covered: loadMovie(), variables, conditional clauses, tell targets.
Assumed knowledge: Basic preloader mechanism, loadMovie(), variable manipulation, paths and levels. (See "Related Articles" for links.)

Because this is a preloader tutorial the example swf is 300kB to warrant preloading. To spare those of you who might be on a dialup I've not included it here. To see it in action click here.

You will all need the source however, so download it here.

Known Limitations:
Before we begin I will let you know that there are two limitations which I know of for this preloader.

  • The method described below is for use with multiple child SWFs which you wish to load into one parent SWF, and it works great for this application but you won't be able to run the child SWFs separately if you use this method - they will crash the Flash player. Don't be scared, this is very rarely the case but it's worth noting. Those of you who are competent scripters should consider using my Sequential Preloader which is available here.
  • It wont work for files exported from programs such as Swift3D or Swish unless you reimport them into Flash because you need to be able to add your own preloader and code to the loaded movies. The Sequential Loader mentioned above doesn't have this problem, but is more complicated.
  • It will be hard to have an accurate and dynamic percentage preloader using this method because the movies are all loaded in separate frames and the like. The Sequential Loader mentioned above doesn't have this problem, but is more complicated.
  • This loader will work with movies loaded into target clips on the stage. The code should be almost the same, and I'm sure you can adapt it yourself.

This tutorial deals with a common question I see on forums all about the place. "I've got a movie which consists of a main body movie into which I load lots of little movies and I can't figure out how to preload them all!". Believe it or not, this was the 2nd question I myself asked when I started Actionscripting and I will be forever grateful to the guy who helped me out because he earned me a flipping great wad of cash :o) The solution he gave me, with a few changes, is that which I now bestow upon you dear reader, and it will work in Flash 4 and 5.

When you open up the main.fla from the source file I have provided you will notice 2 layers. The first, named 'Visual' is of no real relevance, it just provides so text while the content is loading, this is where you would insert your fancy little loading animation. The next layer called "Script" contains the important stuff so let's start there. The Script layer must contain one frame for each movie you intend to load. So if your movie loads 10 little movies into it, your script layer must have 10 frames. I also add another frame at the end with just a stop() action for good measure.