Section 10.3. Looping a Series of Frames


10.3. Looping a Series of Frames

Looping replaying a section of your animation over and over againis an efficient way to create long-playing effects for a modest investment of effort and file size .

Say, for example, you want to create a repetitive background effect such as sunlight glinting off water, palm fronds waving in the breeze , or flickering lights. You can create the frames necessary to show the effect briefly (a couple seconds' worth or so), save the frames as a movie clip, and place an instance of that movie clip in one of the layers of your animation so that the effect spans your entire animation. Flash automatically replays the movie clip until you tell it otherwise , so you get an extended effect for a just a few frames' worth of workand just a few frames' worth of file size, too. Such a deal. (For a more in-depth look at movie clip symbols, check out Chapter 7.)


Note: You've seen this kind of looping background effect in action if you've ever watched The Flintstones or just about any other production cartoon, for that matter. Remember seeing the same two caves shoot past in the background over and over again as Fred chased Barney around Bedrock?

To loop a series of frames using a movie clip symbol:

  1. Open the file loop_no_mc.fla, which you can download from the "Missing CD" page .

    On the Stage, you see a sprinkling of white stars on a blue background. In the Library, you see four symbols, including the blink_lights movie clip symbol (Figure 10-14).

    Since you've never seen this movie clip before, take a look at the preview.


    Note: To loop a section of your main Timeline, all you have to do is attach the following action to the last frame of the section you want to loop: gotoAndPlay(1) ;. (If you want your loop to begin at a frame other than Frame 1, replace the 1 in the preceding ActionScript code with the number of the frame at which you want Flash to begin looping.)
    Figure 10-14. Looping a series of frames using a movie clip is super-easy because Flash does all the work. In fact, Flash always assumes you want to loop the movie clips you add to your animations. (If you don't want to loop them, you can tell Flash to stop playing a movie clip after the first time through by attaching the stop( ); action to the last frame of your movie clip symbol.)

  2. In the Library, select the blink_lights movie clip. Then, in the Library's preview window, click the Play icon .

    You see the lights on the cactus change from red to yellow, pink, and blue in rapid succession.

  3. Preview the main animation by selecting Control Test Movie .

    In the test window, you see a lone shooting star streak across the background.

  4. Click the X in the upper-left corner of the test window to return to the workspace .

    First stop: Add an instance of the xmas_cactus movie clip to the animation.

  5. In the xmas_cactus layer, click the first keyframe (Frame 1) to select it. Then, drag the blink_lights movie clip from the Library to the Stage .

    Choose Control Test Movie again to see the results. In the test window that appears, you see the lights on the cactus blink repeatedly as the shooting star moves across the screen.


Note: If you don't want your movie clip to loop, you need to tell Flash to stop playing the movie clip after the first time through. To so instruct it, attach the stop( ) ; action to the last frame of your movie clip symbol ( not the movie clip instance).
DESIGN TIME
Power to the People

One of the beefs some people have with Flash is that the Flash Player embedded in Internet Explorer (and other Web browsers) doesn't automatically show Play, Stop, Rewind, and Pause buttons . So unlike watching an animation play in, say, Windows Media Player, your audience has no control over Flash animation playbackunless you give it to them by creating interactive (object-based) scripts, which you should get into the habit of doing.

(Theoretically, your audience can view a context menu that lets them interact with your animation by right-clicking your animation if they're running Windows, and Control-clicking your animation if they're running Mac. But because few audience members know thisand because Flash gurus who also happen to be expert ActionScript coders can modify, rearrange, add to, and delete menu optionscontext menus aren't particularly useful when it comes to providing consistent playback control.)

Giving your audience as much control as possible is always a good idea, but it's crucial if you're planning to put your Flash animation on the Web. You can't possibly know your Web audience's hardware configuration.

Say, for example, you create a splash page animation with a Stage size of 550 x 400 pixels, and a file size of 10 megabytes. Someone accessing your animation on a handheld, over a slow connection, or on a machine that's already maxed out running 10 other resource-hogging applications won't be able to see the animation you see on your machine.

But even if everyone on the planet had a high-speed connection and the latest computer hardware, giving your audience control would still be important. Why? Because no matter how kick-butt your animation is, by the 23rd time through, it's going to wear a little thin. If you don't offer at least one of the options listed below, you risk turning away repeat visitors :

  • The ability to bypass your animation entirely and go straight to the site's home page

  • The ability to stop and restart the animation

  • The ability to choose which sections of your animation to play

  • The ability to choose a low-bandwidth, reduced-length, or small-screen version of your animation

To add buttons, hotspots, text fields, and other controls that let your audience control the way they interact with your animation, you use object-based scripts . (Object-based scripts are so called because you attach the scripts directly to the objects, such as buttons, with which you want your audience to interact.)

To create automatic effects, such as reversing a movie clip or loading a Web page when your animation reaches Frame 12, you attach a script to a frame to create a frame-based script. Section 10.2.2.2 has an example of a frame-based script.