ActionScript 2.0 Components Language Reference |
|
|
|
| Menu component > Menu.addMenuItem() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
Usage 1:
menuInstance.addMenuItem(initObject)
Usage 2:
menuInstance.addMenuItem(childMenuItem)
initObject An object containing properties that initialize a menu item's attributes. See About menu item XML attributes.
childMenuItem An XML node object.
A reference to the added XML node.
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.
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();
|
|
|
|