Set menu to toggle menu item
<?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" openType="1" />
<submenu label="Pdf" openType="2" toggled="true" />
</submenu>
</menuitem>
</mx:XMLList>
</mx:XMLListCollection>
<mx:Script>
import mx.controls.Alert;
import mx.controls.Menu;
import mx.events.MenuEvent;
private function showMenu():void
{
var myMenu:Menu = Menu.createMenu(myButton, myMenuData);
myMenu.labelField="@label";
myMenu.addEventListener("itemClick",handleMenuClick);
myMenu.show();
}
private function handleMenuClick(evt:MenuEvent):void
{
mx.controls.Alert.show(evt.item.@label);
lastEvent.text = "Selection:" + evt.item.@label + ", Position: " + evt.index + " Type:" + evt.item.@openType;
}
</mx:Script>
<mx:Button id="myButton" label="Display Menu" click="showMenu()" />
<mx:Label id="lastEvent" />
</mx:Application>
Related examples in the same category