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

Chapter 13. Interactivity with Objects > Using Multiple Mouse Event Handlers

Using Multiple Mouse Event Handlers

You can make a single button respond differently to different mouse events by placing several handlers in the button’s ActionScript. You could, for example, create one action set that jumps Flash to the next scene when the user clicks and then releases the mouse button within the active button area. You could create a second action set that opens a new movie with help information in a separate window if the user clicks within the button area but then drags the pointer out of the button area before releasing the mouse button. And you could deliver yet another action if the user presses a key on the keyboard, such as jumping to a frame that displays the message “You must click the button to move to the next question.”

To vary a button’s response to different mouse events:

1.
Open a new copy of the ObjectActions Template that you created earlier in this chapter (a movie with five keyframes and a stop action in Keyframe 1).

2.
In Keyframe 1, select the button on the Stage.

3.
Access the Actions-Button panel.

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

5.
In the Event section of the parameters area, uncheck the Release checkbox, and check the Roll Out checkbox.

6.
From the Add menu, choose Actions > Movie Control > goto.

7.
In the parameters area, do the following:

  • Choose the radio button named Go to and Stop.

  • From the Type pop-up menu, choose Frame Number.

  • Enter 2 in the Frame field.

    Flash adds gotoAndStop (2); to Line 2 in the Script pane between the curly braces of the event handler (Figure 13.26).

    Figure 13.26. This set of actions tells Flash to jump to Frame 2 if the user rolls the pointer into and then out of the active button area.


8.
In the Script pane, select the closing curly brace (Line 3).

9.
Repeat steps 4 and 5, this time choosing the mouse event Press.

Flash adds a second handler— on (press) and a second set of curly braces—to the bottom of the Script pane (Figure 13.27).

Figure 13.27. To add a second set of actions with a different mouse-event trigger, in the Script pane, select the closing curly brace of the first handler (top). From the Add menu, choose Actions > Movie Control > on, and select a new event (bottom).


10.
With on (press) selected, from the Ad menu, choose Actions > Movie Control > goto.

11.
In the parameters area, do the following:

  • Choose the radio button named Go to and Stop.

  • From the Type pop-up menu, choose Frame Number.

  • Enter 3 in the Frame field.

    Flash adds gotoAndStop (3); to Line 5 in the Script pane, placing the action between the second set of curly braces (Figure 13.28).

    Figure 13.28. The second set of actions in the Script pane tells Flash to jump to Frame 3 if the user clicks within the active button area.


    You’re ready to see the button in action.

12.
Choose Control > Test Movie.

Flash exports the movie and opens it in Flash Player. If you move the mouse so that the pointer rolls into and then out of the active button area, Flash jumps to Frame 2. If you click within the active button area, Flash immediately jumps to Frame 3, even before you release the mouse button.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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