Using Menu in Flash CS3
In Getting Started, we created a simple Menu with some colors to choose from. Let's reuse the Menu we created but make it actually do something.
Note: Please be sure that the Menu component appears in your library, or your project will not run correctly. To begin, let's import everything we'll be using in this tutorial, so that's one less thing to worry about. Just place this code at the top of everything.
Now let's create a menu "out of the blue" and give it an array of colors.
Next, let's add a Button component. Since we're going to instantiate it in ActionScript like we did with the Menu, drag the Button component from the Components panel into your library. But if you don't like code, its certainly possible to drag it onto the stage instead. Just give it the same name as below ("button").
Since menus are naturally shy and don't initially display, let's make the button pop up the menu by adding an event listener. (Menus are also good at taking orders.)
The function named
showMenu will be called when the button gets clicked, and will display to the bottom of the button. Next, let's create a text field on the stage which we'll use later.
Now let's make something happen when a menu item is selected.
Now when a menu item is selected, the color choice will be displayed on the stage. That's it! The complete code is below:
To see a live example, please install Adobe Flash Player version 9 or higher.
Download the FLA file.
For additional information, please take a look at the Examples section for functional demonstrations and the ActionScript 3.0 Class Reference for full details on every property, method, and style available to the Menu component.