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.4. Making Dependent Menus

Problem

You want to make the items in one menu (list box or combo box) dependent on the user’s selection in another form element.

Solution

Create a custom makeDependent( ) method for all combo boxes and list boxes.

Discussion

Making a menu depend on the value of another form element is a common practice. For example, you might want to present a list of minivans instead of sports cars if the customer indicates that safety and seating capacity are his top priorities when choosing a new car.

You can create a dependent menu by following these steps:

  1. Create an array of data providers (i.e., an array of arrays) for the dependent menu. Each data provider element should correspond to an item in the master menu. In other words, the index of each data provider element should match up with the index of an item in the master menu.

  2. Define the setChangeHandler( ) method of the master menu so that it automatically calls a function when the user selects an item from the master menu.

  3. In the callback function, use the getSelectedIndex( ) method to determine the selected index of the master menu. Then set the data provider of the dependent menu to the element from the data providers array of the same index.

This feature set is much easier to implement if you make a custom makeDependent( ) method for FSelectableListClass. This class is the superclass for both list boxes and combo boxes, so our custom method is available to both kinds of menus. The makeDependent( ) method should ...

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