Adding Actions to Movie Clips

I l @ ve RuBoard

Just as you can at ach ActionScripts to button instances, you can at ach ActionScripts to movie-clip instances. Movie-clip ActionScripts have a default handler onClipEvent that encompasses its own set of event parameters. The onClipEvent handler can respond to mouse events (such as pressing the mouse button or moving the mouse), keyboard activity (such as pressing a certain key), the activity of the movie clip itself (such as loading into the main Timeline), and the receipt of data (from variables ).

To add an event handler to a movie-clip instance:

  1. Open a new document.

  2. In Frame 1, place an instance of a movie-clip animation on the Stage.

  3. Select the movie-clip instance.

  4. Access the Actions panel.

    The panel's title bar changes to Actions-Movie Clip.

  5. From the Add menu, choose Actions > Movie Clip Control > onClipEvent .

    Flash places the default movie-clip handler onClipEvent (load); and a pair of curly braces in the Script pane (Figure 13.40).

    Figure 13.40. With a movie clip selected on the Stage, when you choose Actions > Movie Clip Control > onClipEvent from the Actions panel's Add menu, Flash adds the default movie-clip event handler onClipEvent ( load ) to the Script pane. This handler causes the script to trigger when the clip loads.

    graphics/13fig40.gif

    The default movie-clip event handler tells Flash to implement the ActionScript within the braces as soon as the movie clip loads into the frame containing it (in this case, Frame 1) during playback of the movie.

Terminology: Clip Event Parameters

The onClipEvent action has nine parameters. The parameters tel Flash when to run the ActionScript that falls within the curly braces of the movie-clip handler statement. Some parameters are pairs of opposite events, such as Load and Unload ; others require further scripting to create a precise event trigger. If you want to trigger an ActionScript with a particular key, for example, you must add to the Key Press statement other actions that test to see what key the user has pressed.

Load triggers the ActionScript when the playhead reaches the first frame in the Timeline containing that movie clip and the clip appears. Unload triggers when the playhead reaches the first frame that no longer contains that movie clip.

Enter Frame triggers the ActionScript when each new frame of the movie clip appears.

Mouse Down/Mouse Up triggers the ActionScript when the user presses/ releases the mouse button anywhere in a frame that contains the movie clip.

Mouse Move triggers the ActionScript when the user moves the mouse anywhere in a frame that contains the movie clip.

Key Down/Key Up triggers the ActionScript when the user presses/releases a key on the keyboard while a frame that contains the movie clip appears.

Data triggers the ActionScript when the script of another object or movie passes variables to the current movie.

You can change the movie clip's handler so that it responds to another event.

To change the movie-clip handler:

  1. Continuing with the file you created in the preceding exercise, in the Script pane, select the movie-clip event handler (Line 1).

    The event parameters for the onClipEvent action appear in the parameters area.

  2. Click the Mouse Down radio button. The first line of code in the Script pane updates to reflect the new event parameter. It now reads onClipEvent (mouseDown){ (Figure 13.41).

    Figure 13.41. Selecting Mouse Down as the triggering event changes the ActionScript. Now the script will trigger whenever someone clicks anywhere in the playback window while the movie clip is present.

    graphics/13fig41.gif

    In the final published movie, this script will trigger whenever this movie clip is in the current frame and someone clicks the mouse button anywhere in the movie-display area.

You're ready to make your clip script do something.

To add an action to be triggered by the movie-clip's event handler:

  1. Continuing with the file from the preceding exercise, with the movie clip selected on the Stage, from the Add menu, choose Actions > Movie Control > stop .

    Flash places stop () ; in Line 2 in the Script pane. You're ready to test your movie.

  2. From the Control menu, choose Test Movie.

    The move opens in Flash Player, displaying the animation contained in the movie clip. When you click anywhere in the Flash Player window, Flash stops the animation cold.

Note that when you use onClipEvent , the triggering mouse event doesn't have to happen inside the area occupied by the movie clip. To tie the mouse input to the location of the movie clip, you need to use the on event handler. The next section shows you how.

I l @ ve RuBoard


Macromedia Flash MX for Windows and Macintosh. Visual QuickStart Guide
Macromedia Flash MX 2004 for Windows and Macintosh (Visual QuickStart Guides)
ISBN: 0582851165
EAN: 2147483647
Year: 2002
Pages: 243

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