MenuBar.addMenuAt()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

Usage 1:

menuBarInstance.addMenuAt(index, label)

Usage 2:

menuBarInstance.addMenuAt(index, label, menuDataProvider)

Parameters

index An integer indicating the position where the menu should be inserted. The first position is 0. To append to the end of the menu, call MenuBar.addMenu(label).

label A string indicating the label of the new menu.

menuDataProvider An XML or XMLNode instance that describes the menu. If the value is an XML instance, the instance's first child is used.

Returns

A reference to the new Menu object.

Description

Method; Usage 1 adds a single menu and menu activator at the specified index with the specified label. Usage 2 adds a single menu and a labeled menu activator at the specified index. The content for the menu is defined in the menuDataProvider parameter.

Example

Usage 1: The following example places a menu in the first position on the MenuBar instance my_mb.

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.addMenuAt(0, "Flash");
my_menu.addMenuItem({label:"About Adobe Flash", instanceName:"aboutInst"});
my_menu.addMenuItem({label:"Preferences", instanceName:"PrefInst"});

Usage 2: The following example adds an Edit menu with the menu items Undo, Redo, Cut, and Copy, which are defined in the XML data provider myDP_xml. It adds the menu to the first position of the MenuBar instance my_mb.

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({label:"Undo", instanceName:"undoInst"});
myDP_xml.addMenuItem({label:"Redo", instanceName:"redoInst"});
myDP_xml.addMenuItem({type:"separator"});
myDP_xml.addMenuItem({label:"Cut", instanceName:"cutInst"});
myDP_xml.addMenuItem({label:"Copy", instanceName:"copyInst"});

my_mb.addMenuAt(0, "Edit", myDP_xml);