To use XML data from a server to create and populate a menu:
Select File > New and create a Flash document.
1.
Drag the Menu component from the Components panel to the Stage and delete it.
2.
This adds the Menu component to the library without adding it to the application. Menus are
created dynamically through ActionScript.
In the Actions panel, add the following code to the first frame to create a menu and add
3.
some items:
var myMenu = mx.controls.Menu.createMenu();
// Import an XML file
var loader = new XML();
loader.menu = myMenu;
loader.ignoreWhite = true;
loader.onLoad = function(success) {
// When the data arrives, pass it to the menu
if(success) {
this.menu.dataProvider = this.firstChild;
}
};
loader.load(url);
Note: The menu items are described by the children of the XML document's first child.
Select Control > Test Movie.
4.
To use a well-formed XML string to create and populate a menu:
Select File > New and create a Flash document.
1.
Drag the Menu component from the Components panel to the Stage and delete it.
2.
This adds the Menu component to the library without adding it to the application. Menus are
created dynamically through ActionScript.
In the Actions panel, add the following code to the first frame to create a menu and add
3.
some items:
// Create an XML string containing a menu definition
var s = "";
s += "<menu>";
s += "<menuitem label='Undo' />";
s += "<menuitem type='separator' />";
s += "<menuitem label='Cut' />";
s += "<menuitem label='Copy' />";
s += "<menuitem label='Paste' />";
s += "<menuitem label='Clear' />";
s += "<menuitem type='separator' />";
s += "<menuitem label='Select All' />";
s += "</menu>";
// Create an XML object from the string
var xml = new XML(s);
xml.ignoreWhite = true;
// Create a menu from the XML object's first child
var myMenu = mx.controls.Menu.createMenu(_root, xml.firstChild);
Select Control > Test Movie.
4.
546
Chapter 6: Components Dictionary
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?