7.5. Using Movie Clips as Buttons


You want to use a movie clip as a button.


Use the button event handler methods with the movie clip.


Button symbols are still appropriate choices when you want to create simple, authoring-time buttons with basic button states. However, in most cases, you should use movie clips as buttons instead because movie clips can handle all the button events, and ActionScript gives you much more programmatic control over movie clips than buttons. For example, you can attach movie clips to a timeline from the Library, programmatically control the contents of a movie clip such as text labels, and use drawing methods to draw inside movie clips.

While it is not technically improper to apply event handlers to the physical instances of movie clips on the Stage, using the event handler methods (introduced in Flash MX) offers several advantages. First of all, they enable you to keep your code centralized rather than applying the code to each instance. Furthermore, you can assign event handler methods to dynamically created movie clips as well as manually created instances.

The button event handler methods include those shown in Table 7-2.

Table 7-2. The button event handler methods

Event handler method


onPress( )

Triggered when the user clicks on the instance.

onRelease( )

Triggered when the user releases the mouse following a click on the instance.

onReleaseOutside( )

Triggered when the user releases a mouseclick outside ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.