- Listening for Events
- Mouse Detection
- The SimpleButton Class
- Invisible Buttons
- Animated Buttons and the Movie Clip Symbol
- Complex Buttons
- Button-tracking Options
- Changing Button Behavior
- Creating Buttons Dynamically
- Keyboard Detection
- The Contextual Menu
- Creating Continuous Actions
- A Summary of Events
You can define a button instance in the Properties inspector in one of two ways: Track as Button or Track as Menu Item . These two tracking options determine whether button instances can receive a button event even after the event has started on a different button instance. The Track as Menu Item option allows this to happen; the Track as Button option doesn’t. The default option, Track as Button, is the typical behavior for buttons; it causes one button event to affect one button instance. More complex cases, such as pull-down menus, require multiple button instances working together.
Imagine that you click and hold down the menu button to see the pop-up choices, drag your pointer to your selection, and then release the mouse button. You need Flash to recognize the MouseEvent.MOUSE_UP event in the expanded menu even though the MouseEvent.MOUSE_DOWN event occurred in the collapsed menu for a different button instance (in fact, in a different frame altogether). Choosing Track as Menu Item allows these buttons to receive these events and gives you more flexibility to work with combinations of buttons and events.
To set Track as Menu Item for a pull-down menu
- Continue with the pull-down menu, as described in the preceding task.
- Go to symbol-editing mode for the movie clip.
- Select the keyframe on frame 1 containing the event handler for the button instance, and change the mouse event to MouseEvent.MOUSE_DOWN .
- Select the keyframe containing the ActionScript for the expanded section. Replace all the MouseEvent.CLICK events with MouseEvent.MOUSE_UP .
- Select each button instance in the expanded keyframe.
- In the Properties inspector, choose Track as Menu Item .
The button instances in the expanded menu will now trigger a MouseEvent.MOUSE_UP event even if the MouseEvent.MOUSE_DOWN event occurs on a different instance.
- Return to the main Timeline, and test your movie.
You now click and hold down the mouse button to keep the menu open, and then release the mouse button when you’ve made your selection.