User Guide

906 Menu component (Flash Professional only)
Usage 2:
menuInstance.addMenuItem(childMenuItem)
Parameters
initObject An object containing properties that initialize a menu items attributes. See
About menu item XML attributes” on page 887.
childMenuItem An XML node object.
Returns
A reference to the added XML node.
Description
Method; Usage 1 adds a menu item at the end of the menu. The menu item is constructed
from the values supplied in the
initObject parameter. Usage 2 adds a menu item that is a
prebuilt XML node (in the form of an XML object) at the end of the menu. Adding a
preexisting node removes the node from its previous location.
Example
The following example creates two menus, initially adding one menu item to each. The
example then adds two more menu items to the first menu, calling
addMenuItem() to add the
first menu item by specifying its attributes. It then adds the second menu item by using the
prebuilt menu item node from the second 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 the Menu objects.
var first_menu:Menu = Menu.createMenu();
first_menu.addMenuItem({label:"1st Item"});
var second_menu:Menu = Menu.createMenu();
second_menu.addMenuItem({label:"1st Item 2nd Menu"});
// First usage method
first_menu.addMenuItem({label:"Radio Item", instanceName:"radioItem1",
type:"radio", selected:false, enabled:true, groupName:"myRadioGroup"});
// Second usage method
first_menu.addMenuItem(second_menu.getMenuItemAt(0));
// Show menu.
first_menu.show();