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:
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.
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.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 ...
Get Actionscript 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.