ActionScript 2.0 Components Language Reference |
|
|
|
| Menu component > MenuDataProvider.getMenuItemAt() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
myMenuDataProvider.getMenuItemAt(index)
index An integer indicating the position of the menu.
A reference to the specified XML node.
Method; returns a reference to the specified child menu item of the current menu item.
Any node or menu item in a MenuDataProvider instance can call the methods of the MenuDataProvider class.
The following example creates a menu, adds a menu item to it, and then calls the getMenuItemAt() method to access its node object for the purpose of adding a submenu item to it. It also calls the getMenuItemAt() method to display the label of the submenu item 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"});
var menuItem_obj:Object = menuDP_obj.getMenuItemAt(0);
menuItem_obj.addMenuItem({label:"Submenu Item"});
menuDP_obj.addMenuItem({label:"2nd Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Show and position the menus.
my_menu.show(100, 20);
// Retrieve the submenu item from the 1st menu item.
var myMenuItem_obj:Object = menuDP_obj.firstChild;
trace(myMenuItem_obj.getMenuItemAt(0));
|
|
|
|