9.2. Creating Buttons that Animate

Problem

You want to create a button that will animate in one, two, or all three of its states.

Solution

Add a movie clip instance to the button’s keyframes in which the movie clip contains animation.

Optionally, use a movie clip and some ActionScript to control the timeline.

Discussion

Buttons (and movie clips with button states) allow you to define only one frame for each of their states, and that limitation may at first appear to be a challenge when you want to add animations to your button states. However, you can achieve this goal by adding movie clip instances containing animation to the keyframes of the symbol’s timeline. This trick works because a movie clip’s timeline can play independently of the timeline that contains it.

There are many different combinations to choose from when talking about adding animations to buttons. Some of the more common are as follows:

  • Animate the up state, and have non-animated over and down states. For example, you might have a button that spins until a user moves the mouse over it, at which point it would stop spinning.

  • Animate the over state, but not the up or down states. This is the reverse of the previous scenario. For example, a button could remain static until the user moves the mouse over it, at which point it could begin to spin or animate in some other way.

When a button state is activated, either by the user clicking on the button or moving the mouse over or away from the button, Flash automatically moves ...

Get Flash 8 Cookbook 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.