Button Events

Table 10.1 briefly introduces the various events available for buttons. Using button events, we can easily create code for navigation, forms, games, and other interface elements. Let’s explore each button event and learn how a button can be programmed to react to mouse and keyboard events.

Each of the button events in Table 10.1 is handled by a matching button event handler of the form on (eventName). For example, the press event is handled using an event handler beginning with on (press). The exception is the keyPress event handler which takes the form on (keyPress key) where key is the key to detect. Button events are sent only to the button with which the mouse is interacting. If multiple buttons overlap, the topmost button receives all events; no other buttons can respond, even if the topmost button has no handlers defined. In the following descriptions, the hit area refers to the physical region of the button that must be under the mouse pointer in order for the button to be activated. (A button’s hit area is defined graphically when you create the button in the Flash authoring tool.)

Table 10-1. Button Events

Button Event Name

Button Event Occurs When . . .

press

Primary mouse button is depressed while pointer is in the button’s hit area. Other mouse buttons are not detectable.

release

Primary mouse button is depressed and then released while pointer is in the button’s hit area.

releaseOutside

Primary mouse button is depressed while pointer ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.