User Guide

558 Chapter 6: Components Dictionary
Description
Method (static); instantiates a Menu instance, and optionally attaches it to the specified parent,
with the specified MenuDataProvider as the data source for the menu items.
If the
parent parameter is omitted or null, the Menu is attached to the _root Timeline.
If the
mdp parameter is omitted or null, the menu does not have any items; you must call
addMenu() or setDataProvider() to populate the menu.
Example
In the following example, line 1 creates a MenuDataProvider instance, which is an XML object
that has the methods of the MenuDataProvider class.
In the following example, the first line creates an XML object instance, which is given the
methods of the MenuDataProvider class (because the MenuDataProvider class is a decorator class
of the XMLNode class). The next line adds a menu item (New) with a submenu (File, Project,
and Resource). The next block of code adds more items to the main menu. The third block of
code creates an empty menu attached to
myParentClip, fills it with the data source myMDP, and
opens it at the coordinates (100,20):
var myMDP:XML = new XML();
var newItem:Object = myMDP.addMenuItem({label:"New"});
newItem.addMenuItem({label:"File..."});
newItem.addMenuItem({label:"Project..."});
newItem.addMenuItem({label:"Resource..."});
myMDP.addMenuItem({label:"Open", instanceName:"miOpen"});
myMDP.addMenuItem({label:"Save", instanceName:"miSave"});
myMDP.addMenuItem({type:"separator"});
myMDP.addMenuItem({label:"Quit", instanceName:"miQuit"});
var myMenu:mx.controls.Menu = mx.controls.Menu.createMenu(myParentClip,
myMDP);
myMenu.show(100, 20);
To test this code, place it in the Actions panel on Frame 1 of the main Timeline. Drag a Menu
component from the Components panel to the Stage and delete it. (This adds it to the library
without placing it in the document.)
Menu.dataProvider
Availability
Flash Player 6 (6.0 79.0).
Edition
Flash MX Professional 2004.
Usage
myMenu.dataProvider