Menu with event listener : Menu Event « Components « Flex






Menu with event listener

Menu with event listener
      
<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
        
        import mx.controls.Menu;
        import mx.events.MenuEvent;
        
        private function createAndShow():void {
            var myMenu:Menu = Menu.createMenu(null, myMenuData, false);
            myMenu.labelField="@label"
        
            myMenu.addEventListener(MenuEvent.ITEM_CLICK,itemClickInfo);
            myMenu.show(225, 10);
        }
        private function itemClickInfo(event:MenuEvent):void {
            ta1.text="event.type: " + event.type;
            ta1.text+="\nevent.index: " + event.index;
            ta1.text+="\nItem label: " + event.item.@label
            ta1.text+="\nItem selected: " + event.item.@toggled;
            ta1.text+= "\nItem type: " + event.item.@type;
        }
      
    </mx:Script>
    <mx:XML id="myMenuData">
        <xmlRoot>
            <menuitem label="MenuItem A">
                <menuitem label="SubMenuItem A-1" enabled="false" />
                <menuitem label="SubMenuItem A-2" />
                <menuitem label="SubMenuItem A-3" />
                <menuitem label="SubMenuItem A-4" />
                <menuitem label="SubMenuItem A-5" />
                <menuitem label="SubMenuItem A-6" />
                <menuitem label="SubMenuItem A-7" />                
            </menuitem>
            <menuitem label="MenuItem B" type="check" toggled="true" />
            <menuitem label="MenuItem C" type="check" toggled="false" />
            <menuitem type="separator" />
            <menuitem label="MenuItem D">
                <menuitem label="SubMenuItem D-1" type="radio" groupName="one" />
                <menuitem label="SubMenuItem D-2" type="radio" groupName="one" toggled="true" />
                <menuitem label="SubMenuItem D-3" type="radio" groupName="one" />
            </menuitem>
        </xmlRoot>
    </mx:XML>
    <mx:Button x="10" y="5" label="Open Menu" click="createAndShow();" />
    <mx:TextArea x="10" y="40" width="200" height="100" id="ta1" />
</mx:Application>

   
    
    
    
    
    
  








Related examples in the same category

1.Get menu label from click eventGet menu label from click event
2.Menu event indexMenu event index
3.change event for MenuBarchange event for MenuBar
4.itemRollOver event for MenuBaritemRollOver event for MenuBar
5.Menu item click eventMenu item click event
6.Menu show eventMenu show event
7.Menu hide eventMenu hide event
8.Menu roll out eventMenu roll out event
9.Menu Item Roll Over eventMenu Item Roll Over event
10.Show the detailed information for MenuEvent
11.Create EventHandlers for Menu-Based ControlsCreate EventHandlers for Menu-Based Controls
12.A menu with a simple event listener.A menu with a simple event listener.
13.Handle events for the menu bar and for the pop-up submenus.Handle events for the menu bar and for the pop-up submenus.
14.Using Menu control eventsUsing Menu control events
15.Menu labelFieldMenu labelField