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

Event Handlers

Event handlers are actions that control the response to certain things, called events, that the viewer does in a Flash movie. Pressing and releasing the mouse button and pressing a key on the keyboard are all examples of events. Event handlers detect these events and perform certain actions as a response. For example, in the previous tasks, you assigned actions to buttons that detect the mouse release event. In response, you had Flash go to either the expanded keyframe or the collapsed keyframe.

Mouse events are all the events associated with the movements and button clicks of the viewer's mouse. When you assign an action to a button instance, Flash automatically brackets that action with the default mouse event Release:

on (release) {

}

The Release mouse event is the typical trigger for mouse interactivity. When the mouse button is released inside the Hit state of a button symbol, any action within the curly braces is performed. This allows viewers to change their mind and release the mouse button over a safe spot outside the Hit area even after they've already clicked a button. Other types of mouse events make possible a range of mouse interactions. All the mouse events are listed in Table 4.1.

Table 4.1. Mouse Event Descriptions
Mouse Event Triggered when
on (press) When the pointer is over the Hit area and the mouse button is depressed.
on (release) When the pointer is over the Hit area and the mouse button is depressed and released.
on (releaseOutside) When the pointer is over the Hit area, then the mouse button is depressed, then released outside of the Hit area.
on (rollOver) When the pointer moves over the Hit area.
on (rollOut) When the pointer moves from the Hit area off the Hit area.
on (dragOver) When the pointer is over the Hit area, and the mouse button is depressed, then the pointer is moved off the Hit area and back over the Hit area while the button remains depressed.
on (dragOut) When the pointer is over the Hit area, and the mouse button is depressed, then the pointer is moved off the Hit area while the button remains depressed.


To select a mouse event:

1.
In the Actions panel in Normal mode, select Actions > on. In the Parameters pane, the different kinds of events appear with checkboxes (Figure 4.28).

Figure 4.28. The Parameters area of the on action contains a checkbox list of the various events.


2.
Check the event you want, based on the interaction you require.

3.
Choose an action as a response to the selected event.

4.
From the Control menu, choose Test Movie to see the behavior of different mouse events (Figure 4.29).

Figure 4.29. The pull-down menu with the Roll Over event. When the mouse simply moves over the top button, the menu immediately expands.


Tip

All the mouse events except Release require that you use Control > Test Movie in order to see the behavior of the button instance. These mouse events don't work in the editing environment when you choose Control > Enable Simple Buttons.


Tip

It's possible to assign more than one selection of mouse events within one on action. For example, the action on (press, release) will detect when the mouse is depressed as well as when the mouse is released, and will execute any action within its curly braces if either of those two mouse events occurs (Figure 4.30).

Figure 4.30. If the Press event or the Release event is detected, this script will carry out the action play.



Tip

Within one button instance, if you want one event to have a different consequence from another event, you must create separate on action statements. For example, to have the Roll Over event make your movie play and the Roll Out event make your movie stop, your actions would look like this:

on (rollOver) {
    play ();  

}

on (rollOut) {
    stop ();
}


Tip

Don't confuse the Roll Over mouse event with the Over keyframe of your button symbol. Both involve detecting when the pointer is over the Hit area, but the Over state describes how your Button looks when the mouse is over the Hit area while the Roll Over mouse event assigns an action when that event actually occurs. So the keyframes of a button symbol define how it looks, and the mouse-event action defines what it does (Figure 4.31).

Figure 4.31. The Over state of the button symbol (top) defines how the button looks when the pointer is over the Hit state. A Roll Over event handler assigned to the instance (bottom) defines what the button does when the pointer is over the Hit state.



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