managing smooth download and display
Because most Flash movies are downloaded and viewed over the web, Flash has a number of advanced Actions that are dedicated solely to controlling the download and display of movies. If Frame is Loaded lets developers prevent a movie from playing before a specified portion of it has finished loading, and Load/Unload Movie allows movies to be broken into small pieces that are downloaded only if required based on the user's navigational choices.

ensuring proper movie playback with if frame Is loaded and the "_framesloaded" property
When Flash movies are played back over the internet, they "stream", meaning that the plug-in shows as much of the movie as it can during download, even if the whole file has not been transferred to the user's system. The benefit of this feature is that users start seeing content without having to wait for the entire movie to finish downloading. But there are potential drawbacks to streaming: first, during streamed playback, the movie may unexpectedly halt at arbitrary points on the timeline because a required portion of the movie has not yet downloaded; second, Actions are ignored when they refer to segments of the movie that have not downloaded. These drawbacks can lead to unpredictable, and often undesired playback results.

Thankfully, there's a solution. You can regulate the playback of the movie by using the "If Frame is Loaded" Action to prevent the movie from playing until a specified portion of it has downloaded. This technique is often referred to as "preloading". A common preload sequence, or "preloader" involves displaying only a short message, such as "Loading…Please Wait", while the movie loads. Once the appropriate amount of the movie has been retrieved, the movie is allowed to play. Flash provides both a basic and an advanced method of producing a preloader.

building a basic preloader
In this example we'll explain how to create a preloader for a 100 frame movie, where the movie doesn't begin playing until all 100 frames have been downloaded.

on the cd-rom
For further study, we've included this basic preloader movie as a sample movie called "basic-preloader.fla" on the Flash Bible CD-ROM in the Chapter 14 folder. Excerpt readers can download the .zip here.

A couple of notes on preloaders: first, preloaders do not work inside Movie Clips. You cannot preload individual portions of a Movie Clip. If a Movie Clip instance is placed on a frame, the frame is not considered loaded until the entire instance has finished loading. Second, you don't need to preload the entire movie when using preloaders. In our example above, you could move the "minimum-loadpoint" keyframe to any point in the movie after frame 5. By using the streaming emulator in Test Movie mode, you can determine approximately how much of your movie should be loaded before you allow it to play. Also, by using more than one preloader you can show the first part of a movie and then re-enter a loading state before showing any subsequent parts.

building a more sophisticated preloader
In Flash 3, the only tool developers had to create preloaders was the If Frame is Loaded Action. Using multiple preloaders, developers attempted to simulate a percentage loaded feature which told the user how much of the movie had been downloaded. Though they demonstrated the ingenuity of the developers, these percentage loaded indicators were mostly inaccurate. But with the introduction of Action Script in Flash 4, developers now have a way to precisely determine the percentage of frames that have been downloaded to the user's system. You'll need to be familiar with Action Script to create your own advanced preloaders, but if you're not, you can still use the template sample file included Flash Bible CD-ROM in the Chapter 14 folder called "advanced-preloader.fla". Excerpt readers can download the .zip here.

Here's an example of how to build one kind of advanced preloader: create a Keyframe where you wish to halt playback until the desired amount of the movie is loaded. Then create a Keyframe somewhere before that Keyframe and label it "preload-loop". Then create a Keyframe where the movie really starts and label it "begin-movie". On the Keyframe where you want playback to halt, add the following Action Script:

Set Variable: "loadedFrames" = GetProperty ("/",_framesloaded)
Set Variable: "totalFrames" = GetProperty ( "/",_totalframes)
If (loadedFrames < totalFrames)
   Set Variable: "percentageOutput" = int((loadedFrames / totalFrames) * 100)
   Go to and Play ("preload-loop")
   Go to and Play ("begin-movie")
End If

Then, on the main stage at the same point as the "preload-loop" Keyframe, create a Text Field Variable called "percentageOutput".

When the playhead reaches the frame on which the above Action Script is placed, Flash executes the script. If, at that time, it finds that the number of frames downloaded is fewer than the number of total frames in the movie, it sends the playhead back to the "preload-loop" Keyframe and updates the percentageOutput variable to show, as a percentage, how many frames have loaded relative to the total number of frames in the movie. If, on the other hand, the number of frames loaded is not less than the total number of frames in the movie (in other words, if all the frames have loaded), then the playhead is moved to the "begin-movie" Keyframe, and the movie proper starts playing.

An interesting variation on this advanced style of preloading is a graphical preload bar. A preload bar would simply be a small Movie Clip which contains a rectangle shape. Once placed on stage, the width of the bar would be set using Set Property to adjust the X Scale (width percentage) Property of the rectangle Movie Clip instance. Excerpt readers can download this excerpt-only .fla file which demonstrates the graphical preloader in action.

Both the text based and graphical advanced preloaders are not accurate measurements of downloaded file size. They measure only the number of frames that have been downloaded. So, if the content of your movie is distributed evenly over the frames of the timeline, the frames-based percentage values will closely match the real file size transfer percentage. If, however, your heaviest content occurs only on sporadic frames, the frames-based percentage values may appear imprecise to the user.


about this info
this documentation is a short excerpt from colin moock's section of the 600 page book "the flash 4 bible", (idg books). to order, or for general information about the book, visit colin's flash 4 bible page.

revision history
november 30, 1999: created.
december 1, 1999: posted.
march 17, 2000: added the graphical preloader sample .fla file.
june 12, 2000: fixed the link to the graphical preloader .zip