• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Hour 14. Using ActionScript to Create No... > Task: Make an Action That Loops Part...

Task: Make an Action That Loops Part of Your Movie

In a new file, use the Text tool to create a text block containing the word Welcome. Select the block and convert to symbol. Make it a Movie Clip and name it Welcome Text.

Position the clip instance in the center of the screen, and insert keyframes at frame 20 and frame 30.

Move the current frame marker to frame 1 and move Welcome Text all the way off stage to the left. Set Motion Tweening for both frame 1 and frame 20. In frame 20, use the Properties panel to make the tween rotate one time clockwise (CW) on its way from frame 20 to frame 30. Look in Hour 8, “Using Motion Tween to Animate,” for a review of this. Test the movie. Notice that the whole movie loops over and over. Instead we're going to make the rotation part (from frame 20 to frame 30) loop forever.

You can add Actions to any keyframes, but instead of mixing Actions with your animation, we can just make a whole new layer exclusively for Actions. Name the single layer “Animation” and then choose Insert, Layer and name the new one “Actions.” Make sure the current layer is Actions (you'll see a pencil in the layer). Select frame 30 in your Actions layer, insert a keyframe (press F6), and then access the Actions panel (either by selecting Window, Actions or right-clicking on the keyframe and selecting Actions). Make sure frame 30 remains selected when you edit the Actions panel (as in Figure 14.2). We're going to set an Action to execute when the playback head reaches frame 30.

Figure 14.2. The Actions panel is opened right after frame 30 is selected so that we can set an Action to execute when the playback head reaches that frame.

To insert a gotoAndPlay Action, click the plus button and then Actions, Movie Control, goto (or “gotoAndPlay” if you don't see goto listed). You should see a gotoAndPlay Action added to your script in the Script Area on the right (see Figure 14.3). The parameters default to what's shown, but we'll edit these. Notice that in the Timeline, a small a appears in the keyframe where you added the Action.

Figure 14.3. The Actions panel immediately after inserting a goto Action.

If your Parameters Area is not revealed, make sure you're in Normal mode by selecting the Options menu or View Options menu (both in the Actions panel).

The Parameters Area is where you specify all the details for the selected Action (gotoAndPlay, in this case). For this exercise, leave most of the defaults but enter 20 in the Frame field. The final Action in the script area should read gotoAndPlay(20) (as shown in Figure 14.4).

Figure 14.4. The finished form of the Action attached to frame 30. Every time the playback head reaches frame 30, it goes back to frame 20 and plays.

Test the movie (don't just play in the authoring environment). It plays once, and then every time it gets to frame 30 it goes back to frame 20 and plays again.

As easy as that exercise was, there is one thing in particular that could make it better. Consider the amount of work involved if you changed the location of the keyframes. For example, what if the second keyframe (frame 20) had to move to frame 25? Of course, the initial tween would take longer to play, and the rotation would be quicker, but the loop would also stop working properly. To fix it, you would need to remember to edit the Action in frame 30 so that it read gotoAndPlay(25);. You would have to repeat this fix every time you changed the location of the keyframe where the rotation starts.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint