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

Using On Mouse Event

When you click a basic Flash button, the press of the mouse button actually triggers Flash to display the Down frame. When you attach an ActionScript to a button, however, the default button handler adds on (release) to the Actions List. That code makes releasing the mouse button the event that triggers the actions. You can change that behavior by selecting a different Event parameter for the button's handler.

To choose the triggering mouse events:

1.
Create a new Flash document with keyframes in frames 1 and 2.

2.
Use the text tool to add text that idengifies each frame (Scene 1•Frame 1 and Scene 1•Frame 2).

3.
Add a stop action to each frame so that the movie doesn't loop through the frames on playback.

4.
Place a single button instance in Frame 1, and select the button.

5.
Access the Object Actions panel.

6.
From the Add Statement menu, choose Basic Actions > On Mouse Event (Figure 13.21).

Figure 13.21. Choose On Mouse Event from the Toolbox List or the Add Statement menu to define a button's triggering mouse event.


Flash adds the button handler— on (release) and a pair of curly braces—to the Actions List. The parameters governing mouse events appear in the Parameters pane. These parameters specify the exact mouse event that will trigger any actions that you add between the handler's curly braces.

7.
In the Event section of the Parameters pane, uncheck the Release checkbox.

8.
Check one or more of the other Event check boxes (Roll Out, for example).

Flash updates the Actions List, adding the specified mouse events within the parentheses. To set multiple parameters for a mouse event—such as making the button respond to a click within the button area as well as to the user's rolling the pointer out of the button area—check more than one box (Figure 13.22).

Figure 13.22. With the mouse-event action selected in the Actions List, you can select one or more triggering mouse events for a button in the Parameters pane.


9.
With on (press, rollOut) { selected in the Actions List, from the Add Statement menu, choose Basic Actions > Go To.

10.
From the Parameters pane's Type menu, choose Next Frame.

The Go To and Play checkbox is grayed out. The button will take you to the next frame and then stop playback.

Flash adds nextFrame (); to the Actions List between the curly braces (Figure 13.23).

Figure 13.23. When Press and Roll Out are selected as On Mouse Event parameters, your viewers can trigger the nextFrame action in two ways: by clicking inside the button area or by rolling the pointer into and then out of the active button area.


You're ready to see the button in action.

11.
Choose Control > Test Movie.

Flash exports the movie and opens it in Flash Player. The button responds to the pointer's rolling into and then out of the button area by taking you to Frame 2 of the movie. Flash also responds to a click within the button area by taking you to Frame 2.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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