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

Chapter 13. Interactivity with Objects > Creating Buttons That Respond to Mouse...

Creating Buttons That Respond to Mouse Events

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.
Create a new Flash document with keyframes in the first three frames.

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

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.

7.
In the Event section of the Parameters pane, uncheck the Release checkbox and check the Roll Out checkbox.

8.
From the Add Statement menu, choose Basic Actions > Go To.

9.
From the Parameters pane's Type menu, choose Frame Number, and enter 2 in the Frame field.

Flash adds gotoAndPlay (2); to the Actions List between the braces of the button handler (Figure 13.24).

Figure 13.24. 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.


10.
In the Actions List, select the closing curly brace.

11.
Repeat steps 6 and 7, 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 Actions List (Figure 13.25).

Figure 13.25. To add a second set of actions with a different mouse-event trigger, in the Actions List, select the closing curly brace of the first handler (top). From the Add Statement menu, choose On Mouse Event and select a new event (bottom).


12.
With on (press) selected, from the Add Statement menu, choose Basic Actions > Go To.

13.
From the Parameters pane's Type menu, choose Frame Number, and enter 3 in the Frame field.

Flash adds gotoAndPlay (3) to the Actions List between the second set of curly braces (Figure 13.26).

Figure 13.26. The second set of actions in the Actions List 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.

14.
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