14.3. Creating a Jump Menu

Problem

You want to create a jump menu—a menu that causes some action to take place as soon as the user makes a selection.

Solution

Use a combo box or a list in conjunction with a listener object.

Discussion

The combo box and list components dispatch change events when the user makes a selection. Therefore, if you use a listener object to handle those events, you can have Flash perform some tasks as soon as the user chooses an item from the combo box or list. This type of functionality is often referred to as a jump menu.

In the following example, a listener object is registered with a combo box named ccbProducts. When the user makes a selection from the combo box, the value is displayed in the Output panel.

	var oListener:Object = new Object();
	oListener.change = function(oEvent:Object):Void {
	  trace(oEvent.target.value);
	};
	ccbProducts.addEventListener("change", oListener);

For more information regarding using listener objects, see Recipe 13.10.

Get Flash 8 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.