User Guide
894 Menu component (Flash Professional only)
To use XML data from a server 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 use
the
dataProvider property to load menu items from a web page:
/**
Requires:
- Menu component in library
*/
import mx.controls.Menu;
var my_menu:Menu = Menu.createMenu();
// Import an XML file.
var myDP_xml:XML = new XML();
myDP_xml.ignoreWhite = true;
myDP_xml.onLoad = function(success:Boolean) {
// When the data arrives, pass it to the menu.
if (success) {
my_menu.dataProvider = myDP_xml.firstChild;
}
};
myDP_xml.load("http://www.flash-mx.com/mm/xml/menu.xml");
// Show and position the menus.
my_menu.show(100, 20);
4.
Select Control > Test Movie.
The xml menu definition from the web page is provided here for your reference:
<?xml version="1.0" ?>
<menu>
<menuitem label="Undo" />
<menuitem type="separator" />
<menuitem label="Cut" />
<menuitem label="Copy" />
<menuitem label="Paste" />
<menuitem label="Clear" />
<menuitem type="separator" />
<menuitem label="Select All" />
</menu>
NOTE
The menu items are described by the children of the XML document’s first child.