O'Reilly logo

Actionscript Cookbook by Joey Lott

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

11.3. Adding Menus to a Form

Problem

You want to add menus to your form.

Solution

Use combo boxes or list boxes.

Discussion

You can choose from two types of form menus in your Flash movies: combo boxes and list boxes. A combo box is analogous to the standard HTML <SELECT> tag, which is often referred to as a pop-up menu or drop-down list. A combo box allows a user to select one item at a time, and it displays only the selected item when the menu is not in use. Additionally, if you set a combo box’s editable property to true (using setEditable(true)), the user can enter a value by typing it into the text area associated with the combo box.

You can populate a combo box one item at a time using the addItem( ) and addItemAt( ) methods. However, it is usually easier to use the setDataProvider( ) method to assign all the menu items at once. You can pass the setDataProvider( ) method a reference to an array or any object that inherits from the DataProvider class, such as a RecordSet object. The combo box is automatically populated with the data provider elements in the order they appear within the data provider object. Here is an example:

// Create a new combo box.
_root.attachMovie("FComboBoxSymbol", "myComboBox_cb", 1);

// Place the combo box at (100,100).
myComboBox_cb._x = 100;
myComboBox_cb._y = 100;

// Create an array to use as the data provider.
menuItems = ["item a", "item b", "item c", "item d"];

// Populate the combo box.
myComboBox_cb.setDataProvider(menuItems);

A list box ...

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