User Guide

916 Menu component (Flash Professional only)
Description
Method; returns the index of the specified menu item within this menu instance.
Example
The following example creates a menu with two items from an XML data provider and then
adds a third item to the menu and saves the reference that is returned by the
addMenuItem()
method. Next, it calls the
indexOf() method by using the reference to obtain the index of the
item and display it in the Output panel.
You first drag a Menu component and a Button component to the library and then add the
following code to Frame 1:
/**
Requires:
- Menu component in library
*/
import mx.controls.Menu;
// Create an XML object to act as a factory.
var my_xml:XML = new XML();
// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var menuDP_obj:Object = my_xml.addMenuItem("Edit");
// Add the menu items.
menuDP_obj.addMenuItem({label:"1st Item"});
menuDP_obj.addMenuItem({label:"2nd Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
var myItem_obj:Object = my_menu.addMenuItem({label:"That item"});
// Show and position the menus.
my_menu.show(100, 20);
var myIndex_num:Number = my_menu.indexOf(myItem_obj);
trace("Index of 'That Item': " + myIndex_num);