Targeting Movie Clips with Behaviors


In this section, you learn how to include the same interactivity of the previous exercise using Flash 8's behaviors feature. Behaviors, as we discussed in the last chapter, are self-contained blocks of ActionScript code that you can easily apply to elements in your Flash movie. In the following steps, you use behaviors instead of hand-coded actions to stop Stella's tail from wagging during the bark cycle.

On the CD-ROM 

As the starter file for this exercise, use the stella_absolute.fla document in the ch19/stella folder of this book's CD-ROM.

  1. Open the stella_absolute.fla document, and double-click the mcStella instance on the Stage.

  2. On the stellaClip timeline, double-click the mcBarkAnim instance (that is, Stella's head).

  3. On the barkAnimClip timeline, select frame 14 on the topmost actions layer. Open the Actions panel (F9), select the existing ActionScript code in the Script pane, and press the Delete or Backspace key to erase the code. Close the Actions panel when you're finished.

  4. Rename the topmost actions layer to behaviors. Re-select frame 14 of this layer, and open the Behaviors panel (Shift+F3). Click the Add Behavior (+) button and choose Movieclip ð Goto and Stop at frame or label. In the dialog box for this behavior, you'll notice a similar interface to that of the Insert Target Path dialog box. Expand the mcStella node, and choose the mcTailAnim instance. In the frame field, type the number 2. See Figure 19-7 for a review of the settings. Click OK to accept the settings.

  5. Select frame 20 of the lower actions layer, and erase the existing ActionScript code on this keyframe, as you did in Step 3.

  6. Rename the lower actions layer behaviors. With frame 20 of the lower behaviors layer selected, click the Add Behavior (+) button in the Behaviors panel, and choose Movieclip ð Goto and Play at frame or label. In this behavior's dialog box, expand the mcStella node, and choose the mcTailAnim instance. In the frame field, type the number 2. See Figure 19-8. Click OK to accept the settings.

    Tip 

    You can review the ActionScript code that the behavior uses by selecting its keyframe in the Timeline window and opening the Actions panel. Do not edit this code, however, or the behavior will not likely function properly.

  7. Save your document as stella_behaviors.fla, and choose Control ð Test Movie. The Flash movie should operate the same as the movie you created in the last section. When Stella barks, the tail stops wagging. When the bark is finished, the tail resumes wagging.

image from book Figure 19-7: The Goto and Stop at frame or label behavior settings

image from book Figure 19-8: The Goto and Play at frame or label behavior settings

On the CD-ROM 

You can find the completed example, stella_behaviors.fla, in the ch19/stella folder of this book's CD-ROM.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net