Get clicked menu item index, label, toggle state : Menu « Components « Flex






Get clicked menu item index, label, toggle state

Get clicked menu item index, label, toggle state
      
<?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.Add icons to menuAdd icons to menu
2.Add submenu to submenuAdd submenu to submenu
3.Show menuShow menu
4.Define properties and reference in actionscriptDefine properties and reference in actionscript
5.Set menu to toggle menu itemSet menu to toggle menu item
6.Radio button menu itemsRadio button menu items
7.Using a nested array to drive a menu
8.CheckBox MenuItemCheckBox MenuItem
9.Creating a model that a menu uses to drive its display
10.Creating a menu from scratchCreating a menu from scratch
11.Compact way to initialize and display the menu all at onceCompact way to initialize and display the menu all at once
12.Set Menu style for disabled colorSet Menu style for disabled color
13.Show Menu at positioinShow Menu at positioin
14.Disable a menu itemDisable a menu item
15.Model for MenuModel for Menu
16.Add click listener to MenuAdd click listener to Menu
17.Submenu and radio button menuSubmenu and radio button menu
18.CheckBox menuCheckBox menu
19.Menu Control style settingMenu Control style setting
20.Adding icon to MenuitemAdding icon to Menuitem
21.Menu item click handlerMenu item click handler
22.Put Menu, TextInput and Button to ControlBarContentPut Menu, TextInput and Button to ControlBarContent
23.Creating a simple Menu controlCreating a simple Menu control