Home >> Production >> Flash and ActionScript >> ActionScript Part IV

ActionScript: Basic Actions part IV

  • preloaders

Continued

Flash movies stream. This means that they begin playing as soon as enough bytes have downloaded. But sometimes, if your movie is especially large, this causes pauses in the playback as the user's computer waits for more information to download.

By creating a preloader, you set the movie up so that it checks to see that all of the frames of the movie are loaded before it begins to play.

First, you should know how to label frames. In the example below, the movie has 10 frames before the movie starts at the label "start". To assign a label, first create a keyframe in your actions or labels layer (you should always keep actions and labels separate from other layers), and then go to Modify->Frames to bring up the Frames Panel and type your label in the label field.

 

See this movie as an example of a large movie (384 kb) that requires a preloader. In reality, you should never have a movie this large. In this case, I could have reduced the number of bitmaps or compressed the sound further.

Here is the timeline for this movie (Flashmovie1.fla), notice it doesn't start until the start label. Before it plays, it first checks to see that all of the frames in the movie are loaded.

In the first frame there is an action: right-click on the first keyframe in the actions layer and choose actions to bring up the actions editor.

Step One:

Double-click on If Frame Is Loaded on the left side under Basic Actions. At the bottom of the panel, choose Frame Number for the type and in the Frame box type the total number of frames in your movie.

Step Two:

You are constructing a sentence, telling the computer what to do: "If all of the frames in my movie are loaded then start playing the movie."

If frame 200 is loaded, go to and play the label "start"

Double-click Go To and change the type at the bottom to Frame Label and then enter the label of the frame where the movie begins. In our example, we labeled the frame "start."

Step Three:

Now you have told the timeline what to do if the frame is loaded, but what if the frame is not loaded? If it is not loaded, then the timeline will proceed onto the next frame. You need to send the timeline back to Frame 1 if the final frame is not loaded.

The timeline will continue to loop between frames 1 and 2 until the final frame is loaded. Then it will go to and play the movie at the label "start"

In frame 2 of the movie, add another action that says Go To and play frame 1. Do this by double clicking Go To and entering Frame Number 1 at the bottom of the panel.

 

Now the movie will check to see if the last frame of the movie is loaded before playing. If it is loaded it goes to the label "start" and plays. If it is not loaded, it goes to frame 2 which sends it back to frame 1 and process repeats until the whole movie is loaded.

There are fancier things you can do with the preloader action. You can have several stages of preloading by checking to see if a third of the movie is loaded and then proceeding. First watch Flashmovie2.swf and then download Flashmovie2.fla for an identical movie with a more complex preload.

 

These are the actions in the 8 keyframes in the actions layer

The graphic in the loading layer changes as the movie progresses through the preload script.


frame 1 and 2


frame 3 and 4


frame 5 and 6


frame 7 and 8

Other Preloads:

Create a simple preloader using scenes

Simple percentage bar preloader tutorial

Progressive preloader by percents