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

Chapter 13. Interactivity with Objects > Making Movie Clips Act Like Buttons

Making Movie Clips Act Like Buttons

In the preceding exercise, you created a script for a movie clip in which the location of the pointer during the triggering event (the downward click of the mouse button) did not have to coincide with the movie clip’s location. You can use actions to create a script that ties the mouse input directly to the movie clip’s physical location, so that the movie clip acts just like a button.

To create a movie-clip button:

Open a new document.

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

Select the movie clip.

Access the Actions panel.

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

From the Add menu, choose Actions > Movie Control > on.

Flash places the default event handler on (release) in Line 1 in the Script pane (Figure 13.42).

Figure 13.42. You can add the on event handler to movie clips as well as to buttons. Then this handler responds to mouse clicks only when they are directly over the movie clip itself.

The default event tells Flash to implement the ActionScript as soon as the mouse button is clicked and then released while the pointer is within the image area of the movie clip. As you did for buttons earlier in this chapter, you can change the event parameter of the handler so that other mouse actions or keyboard input will trigger the movie-clip button’s script.

In the Script pane, select Line 1.

From the Add menu, choose Actions > Miscellaneous > trace.

Flash adds trace (“”); to Line 2 of the script.

With Line 2 selected, in the parameters area of the Actions-Movie Clip panel, enter text in the Message field—for example, I clicked a butterfly (Figure 13.43).

Figure 13.43. The trace action lets you post messages to the Output window to track which part of your script is executing. You can also use trace to test small sections of code as you build your script.

Choose Control > Test Movie to try out your button movie clip.

In the Flash Player window, position the pointer over various areas of the Stage.

As it moves over the image area of the movie clip, the pointer changes from an arrow to the pointing-finger icon (Figure 13.44). When you click the movie clip, Flash enters the trace message in the Output window (Figure 13.45).

Figure 13.44. In Flash Player, the pointer changes to the pointing-finger icon as it passes over a movie clip whose script starts with the event handler on.

Figure 13.45. The Output window displays whatever message you created for a trace action.



Not a subscriber?

Start A Free Trial

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