Macromedia Flash MX 2004 Tutorial – Part 2

Using Movie Clip Events

The on() and onClipEvent() event handlers can be attached to movie clip instances to trigger both user-initiated and timeline-based actions. For example, you can add an on(release) event to a movie clip instance to trigger an action when the user clicks the movie clip; or, you can add an onClipEvent(load) event to trigger an action when that movie clip loads.

The problem with these event handlers is that they have to be attached to the movie clip instances—you can’t use them to target a movie clip from elsewhere in the movie. Fortunately, the MovieClip object lets you do just that—perform a movie clip action from any keyframe or button instance in the movie. You saw an example of this in the last section, when we used the gotoAndPlay method of the MovieClip object to direct a movie clip instance to begin playing. In addition to events like onLoad, onUnload and onMouseDown, the MovieClip object has a number of properties and methods, which can be referred to using dot syntax. For example: myMovie_mc._alpha = 50; or myMovie_mc.gotoAndPlay(5); This code can be placed anywhere in the movie, as long as the correct path to the movie clip instance is used.

Some of this code is already contained in behaviors, which you can add from the Behaviors panel:

  1. As another simple example, we’re going to add a play button to our car crash movie (assuming we’ve already added a stop() action to the first frame of the bad_driving_mc movie clip to keep it from playing automatically). We’ll select the button on the Stage and open the Behaviors panel.
  2. In the Behaviors panel, click the plus button to add a behavior.
  3. In the menu that appears, select Movie clip and then Goto and Play at frame or label.

  1. In the dialog that opens, select the target movie clip instance and enter the frame or label you want to play:

  1. Click OK.

The behavior now appears in the Behaviors panel:

If you open the Actions panel, you’ll see that the code Flash inserted is identical to the code you added earlier to play a movie clip instance:

Macromedia Flash MX 2004 Part 2: Section 2

In this section, you learned about:

  • Understanding movie clips
  • Using nested symbols
  • Using movie clip events

Leave a Reply

Your email address will not be published. Required fields are marked *