Using Multiple Mouse Event Handlers

I l @ ve RuBoard

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.

      graphics/13fig26.gif

  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 bracesto 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).

    graphics/13fig27.gif

  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.

      graphics/13fig28.gif

      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.

graphics/01icon02.gif Tip

  • Remember that the button you see when you jump to Frame 3 or Frame 2 has no script attached. To try both types of events, you must choose Control > Rewind to return to Frame 1.


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