ActionScript 2.0 Components Language Reference |
|
|
|
| Menu component > MenuDataProvider.indexOf() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
myMenuDataProvider.indexOf(item)
item A reference to the XML node that describes the menu item.
The index of the specified menu item; returns undefined if the item does not belong to this menu.
Method; returns the index of the specified menu item in this parent menu item.
Any node or menu item in a MenuDataProvider instance can call the methods of the MenuDataProvider class.
The following example adds a menu item to a menu and calls the indexOf() method to display the item's index in the Output panel.
You first drag a Menu 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("XXXXX");
// Add the menu items.
menuDP_obj.addMenuItem({label:"1st Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Show and position the menus.
my_menu.show(100, 20);
// Add an item and trace the position of that item.
var myItem_obj:Object = menuDP_obj.addMenuItem({label:"That item"});
var myIndex_num:Number = menuDP_obj.indexOf(myItem_obj);
trace("Position: " + myIndex_num);
|
|
|
|