To use the MenuDataProvider class to create and populate a menu:
1.
Select File > New and create a Flash document.
2.
Drag the Menu component from the Components panel to the library.
Menus are created dynamically through ActionScript.
3.
In the Actions panel, add the following code to the first frame to create a menu and add
some items:
/**
Requires:
- Menu component in library
*/
import mx.controls.Menu;
// Create an XML object to act as a factory.
var xml = new XML();
// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var theMenuElement = xml.addMenuItem("XXXXX");
// Add the menu items.
theMenuElement.addMenuItem({label:"Undo"});
theMenuElement.addMenuItem({type:"separator"});
theMenuElement.addMenuItem({label:"Cut"});
theMenuElement.addMenuItem({label:"Copy"});
theMenuElement.addMenuItem({label:"Paste"});
theMenuElement.addMenuItem({label:"Clear", enabled:"false"});
theMenuElement.addMenuItem({type:"separator"});
theMenuElement.addMenuItem({label:"Select All"});
// Create the Menu object.
var my_menu = mx.controls.Menu.createMenu(_root, theMenuElement);
my_menu.show(100, 20);
4.
Select Control > Test Movie.
896
Menu component (Flash Professional only)
Need help?
Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?
Questions and answers