Compact way to initialize and display the menu all at once
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">
<mx:XMLListCollection id="myMenuData">
<mx:XMLList>
<menuitem label="File">
<submenu label="New" />
<submenu label="Open">
<submenu label="Doc" />
<submenu label="Pdf" />
</submenu>
</menuitem>
</mx:XMLList>
</mx:XMLListCollection>
<mx:Script>
import mx.controls.Menu;
private function showMenu():void
{
var myMenu:Menu = Menu.createMenu(null, myMenuData,true);
myMenu.labelField="@label";
myMenu.show();
}
</mx:Script>
<mx:Button id="myButton" label="Display Menu" click="showMenu()" />
</mx:Application>
Related examples in the same category