Macromedia Flash 8 for Windows & Macintosh

You can make one button respond differently to different mouse events by placing several handlers in the button's script. You can, for example, create a button that jumps Flash to the next frame when the user clicks and then releases the mouse button within the active button area but that pops up the message "You must click the button to move to the next question" if the user presses a key on the keyboard.

To vary a button's response to different mouse events

1.

Open a new copy of the ObjectActionsTemplate that you created earlier in this chapter.

2.

Select the button on the Stage.

3.

In the Actions panel, with Script Assist active, from the Add menu (or the Actions Toolbox) choose Global Functions > Timeline Control > goto.

4.

In the Script Assist window, change the following parameters:

  • Select the Goto and Stop radio button.

  • In the Frame field, enter 4.

Flash adds the script to the Script pane.

5.

In the Script pane, click line 1.

The event handlers appear in the Script Assist window.

6.

Deselect the Release check box, and select the Roll Out check box (Figure 13.37).

Figure 13.37. In Script Assist mode, selecting the event handler line in the script gives you access to other events. Deselect the default Release and select the Roll Out check box to make the button respond to a user's rolling out of the button area.

7.

In the Script pane, click line 3.

Flash highlights the closing curly brace (Figure 13.38). This closing brace marks the end of the actions carried out by on (release).

Figure 13.38. To add a new action statement to your script in Script Assist mode, select the ending curly brace of the existing script. Then choose another action from the Add menu or Actions toolbox.

8.

Repeat step 3 to add another goto action.

Script Assist scripts a new action statement complete with its own event handler and set of braces; Script Assist automatically handles the syntax and placement of the two scripts in relation to one another in the Script pane (Figure 13.39).

Figure 13.39. Flash handles placement of the scripts for multiple action statements. Here are two complete action statements starting with an event handler, followed by a set of braces enclosing the action that should take place when the triggering event occurs.

9.

Repeat step 4; but this time, in the Frame field, enter 5.

10.

In the Script pane, select line 4 (the event handler for the second action statement).

The events appear in the Script Assist window.

11.

Deselect the Release check box, and select the Drag Out check box.

Flash updates the Script pane to reflect the new event. Your script should look like Figure 13.40.

Figure 13.40. This script contains two different event handlers; the button will respond differently to different mouse movements. Contrast this script with the one you created earlier in Figure 13.32 to carry out multiple actions. In that script, multiple action statements appear within one set of curly braces. In this script, multiple sets of curly braces appear, each containing one action.

12.

Choose Control > Test Movie.

Move the pointer so that it rolls into and then out of the button area without your pressing the mouse button; you jump to frame 4. Click the movie button, and then drag out of the button area without releasing the mouse button; you jump to frame 5. When you're done viewing the movie in test mode, close the Flash Player window.

13.

Save your file for use in an upcoming task; name it MultiEventBtn.fla.

Tips

  • When you use the Behaviors panel to add to an existing behavior that uses the default event handler (see the sidebar "Working with Multiple Behaviors"), Flash adds the new action within the curly braces for the existing action statement; it doesn't matter what line of the script was selected initially in the Script pane. To use the Behaviors panel to add a separate action with a different triggering event, you must change the scripted behavior's triggering event before you add the new behavior (see "Changing Events," earlier in this chapter). When the script contains a behavior whose event isn't on (release), Flash adds a new behavior as a separate action statement.

  • When the Behaviors panel contains multiple behaviors, you can control the order in which they're scripted by selecting one of the lines in the Behaviors panel. When you select a new behavior from the Add Behavior menu, Flash adds it to the list before the selected behavior.

Категории