Actionscript Salon #5: Preloading Content

sfmultimedia :: actionscript salons :: preloading content


Actionscript Salon #5: Preloading Content

Almost every new Flash creator is faced with the problem of developing a preloader. This might be as simple as creating a progress bar or a percentage counter. But that’s just the beginning. Whenever we go to the server to request information - whether we’re talking about an external movie, sound, variable file or XML file - we need to give Flash some time to capture and process that information.

This month at the Actionscript Salon, we’ll talk about the nature of preloading: ensuring that content is loaded before it is used. At the end of this Salon, you’ll understand the nature of asynchronous events, and how you can structure your files to avoid many common pitfalls associated with them.

Relevance/availability: The principles of this salon remain unchanged since the day this material was written. The actual code was written for Flash MX 2004 (Player 7), and some techniques used today are very different. AS3 in particular has a unified (and much improved therefore) approach to loading. If you aren't using AS3, however, this material is still very relevant.

Presentation slides (swf)

Note that some of these files are deliberately large-ish (for those on dial-up anyway) in order that the action of preloading may be viewed.

Basic preloader for a movie. This is your basic preloader showing a percentage bar, percentage, bytes loaded and bytes total readouts.

View the swf
Download the fla (Zip 83k)

Basic preloader using loadMovie. This example builds on the previous preloader, but uses loadMovie to load another swf into the main swf.

View the swf
Download the fla (Zip 592k)

MovieClipLoader. Now we're looking at the new MovieClipLoader Object in Flash MX 2004. The methods associated with MovieClipLoader are a bit confusing, but they give information in more useful ways, and are constructed more like the loadVars and XML Objects. You will need Flash Player 7 to see the swf, and Flash MX 2004 to open the file.

View the swf
Download the fla (Zip 626k)

Basic use of LoadVars. LoadVars and XML work in exactly the same fashion from a loading perspective, so I've included only the one example. This example shows how to create and load a LoadVars Object, plan for failure, and grab information out of the received data.

View the swf
Download the fla and related files (Zip 119k)