O'Reilly logo

ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, Keith Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Simple Buttons

Problem

You want to create an interactive button that enables a user to click and perform an action, such as submitting a form or calculating a total.

Solution

Create an instance of the SimpleButton class and create display objects for upState, downState, overState, and hitTestState. Alternatively, create a subclass of SimpleButton that describes your desired button behavior.

Use the click event to invoke a method whenever the user presses the button.

Discussion

The display list model provides an easy way to create buttons through the SimpleButton class. The SimpleButton class allows a user to interact with the display object using their mouse, and makes it easy for you to define that interaction through various button states. The possible button states, listed here, are available as properties of the SimpleButton class:

upState

A display object for the default “up” state of the button. The “up” state is shown whenever the mouse is not over the button.

overState

A display object that determines what the button looks like when the mouse moves over the button. When the mouse leaves the button area, the button moves back to the “up” state.

downState

A display object that’s shown when the button is pressed (or clicked) “down”. When the button is in the “over” state, the “down” state displays when the user presses the left mouse button.

hitTestState

A display object that defines a button’s bounds. When the mouse moves inside of the button’s hit area, the button enters ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required