ActionScript 2.0 Components Language Reference |
|
|
|
| Menu component > MenuDataProvider.addMenuItem() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
Usage 1:
myMenuDataProvider.addMenuItem(initObject)
Usage 2:
myMenuDataProvider.addMenuItem(childMenuItem)
initObject An object containing the attributes that initialize a Menu item's attributes. For more information, see About menu item XML attributes.
childMenuItem An XML node.
A reference to an XMLNode object.
Method; Usage 1 adds a child item to the end of a parent menu item (which could be the menu itself). The menu item is constructed from the values passed in the initObject parameter. Usage 2 adds a child item that is defined in the specified XML childMenuItem parameter to the end of a parent 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 from an XML data provider. It calls the addMenuItem() method to add two items to the main menu and also to add two items to a submenu for the first item of the main menu.
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:"Folders"});
menuDP_obj.addMenuItem({label:"Radio Edit", type:"radio"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Show and position the menu.
my_menu.show(100, 20);
// Retrieve the first menu item and add items into it.
var item_obj:Object = menuDP_obj.getMenuItemAt(0);
item_obj.addMenuItem({label:"First item", instanceName:"firstItem1"});
item_obj.addMenuItem({label:"Second item", instanceName:"secondItem1"});
|
|
|
|