Menu item click handler
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
import mx.events.MenuEvent;
import mx.controls.Alert;
import mx.controls.Menu;
private function showMenu(event:MouseEvent):void{
var navMenu:Menu = Menu.createMenu(this, menuData);
navMenu.labelField="@label";
navMenu.addEventListener(MenuEvent.ITEM_CLICK, menuClickHandler);
navMenu.show(event.stageX,event.stageY);
}
private function menuClickHandler(event:MenuEvent):void{
Alert.show(event.item.@label, "Menu Selection");
}
</mx:Script>
<mx:XMLList id="menuData">
<menuitem label="A">
<menuitem label="A1" view="a1View"/>
<menuitem label="A2" view="a2View"/>
</menuitem>
<menuitem label="B">
<menuitem label="B1Cart" view="b1View"/>
</menuitem>
</mx:XMLList>
<mx:Label text="Click for Menu" mouseUp="showMenu(event)"/>
</mx:Application>
Related examples in the same category