ActionScript 2.0 Components Language Reference |
|
|
|
| MenuBar component > MenuBar.addMenu() | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
Usage 1:
menuBarInstance.addMenu(label)
Usage 2:
menuBarInstance.addMenu(label,menuDataProvider)
label A string indicating the label of the new menu.
menuDataProvider An XML or XMLNode instance that describes the menu and its items. If the value is an XML instance, the instance's first child is used.
A reference to the new Menu object.
Method; Usage 1 adds a single menu and menu activator at the end of the menu bar and uses the specified label. Usage 2 adds a single menu and menu activator that are defined in the specified XML menuDataProvider parameter.
Usage 1: The following example adds a File menu and then uses Menu.addMenuItem() to add the menu items New and Open.
Drag an instance of the MenuBar component onto the Stage, and enter the instance name my_mb in the Property inspector. Add the following code to Frame 1 of the timeline:
/**
Requires:
- MenuBar component on Stage (instance name: my_mb)
*/
var my_mb:mx.controls.MenuBar;
var my_menu:mx.controls.Menu = my_mb.addMenu("File");
my_menu.addMenuItem({label:"New", instanceName:"newInstance"});
my_menu.addMenuItem({label:"Open", instanceName:"openInstance"});
Usage 2: The following example adds a Font menu with the menu items Bold and Italic, which are defined in the XML data provider myDP_xml.
Drag an instance of the MenuBar component onto the Stage, and enter the instance name my_mb in the Property inspector. Add the following code to Frame 1 of the timeline:
/**
Requires:
- MenuBar component on Stage (instance name: my_mb)
*/
var my_mb:mx.controls.MenuBar;
var myDP_xml:XML = new XML();
myDP_xml.addMenuItem({type:"check", label:"Bold", instanceName:"check1"});
myDP_xml.addMenuItem({type:"check", label:"Italic", instanceName:"check2"});
var my_menu:mx.controls.Menu = my_mb.addMenu("Font", myDP_xml);
Usage 3: The following example adds two menus called File and Edit.
Drag an instance of the MenuBar component onto the Stage and enter the instance name my_mb in the Property inspector. Add the following code to Frame 1 of the timeline:
/**
Requires:
- MenuBar component on Stage (instance name: my_mb)
*/
var my_mb:mx.controls.MenuBar;
//Change label text to be read from "name".
my_mb.labelField = "name";
var my_menu:mx.controls.Menu = my_mb.addMenu({name:"File"});
my_menu.addMenuItem({name:"New", instanceName:"newInstance"});
my_menu.addMenuItem({name:"Open", instanceName:"openInstance"});
var my2_menu:mx.controls.Menu = my_mb.addMenu({name:"Edit"});
my2_menu.addMenuItem({name:"Undo", instanceName:"undoInstance"});
my2_menu.addMenuItem({name:"Redo", instanceName:"redoInstance"});
|
|
|
|