change event for MenuBar : Menu Event « Components « Flex






change event for MenuBar

change event for MenuBar
      

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="initCollections();">
    <mx:Script>
        
        import mx.events.MenuEvent;
        import mx.controls.Alert;
        import mx.collections.*;
        [Bindable]
        public var menuBarCollection:XMLListCollection;
        private var menubarXML:XMLList =<><menuitem label="Menu1">
                <menuitem label="MenuItem 1-A" data="1A"/>
                <menuitem label="MenuItem 1-B" data="1B"/>
                </menuitem>
                <menuitem label="Menu2">
                <menuitem label="MenuItem 2-A" data="2A"/>
                <menuitem label="MenuItem 2-B" data="2B"/>
                </menuitem>
                <menuitem label="Menu3" data="M3"/>
                </>
        
        private function initCollections():void {
            menuBarCollection = new XMLListCollection(menubarXML);
        }
        private function changeHandler(event:MenuEvent):void {
            if (event.menu != null) {
                Alert.show("Label: " + event.item.@label + "\n" +"Data: " + event.item.@data, "Clicked menu item");
            }
        }
      
    </mx:Script>
    <mx:Panel title="MenuBar Control Example" height="75%" width="75%" paddingTop="10" paddingLeft="10">
        <mx:Label width="100%" color="blue" text="Select a menu item." />
        <mx:MenuBar labelField="@label"
                    dataProvider="{menuBarCollection}" 
                    change="changeHandler(event);"/>
        <mx:TextArea id="rollOverTextArea" width="200" height="100" />
        <mx:TextArea id="itemClickTextArea" width="200" height="100" />
    </mx:Panel>
</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.Menu with event listenerMenu with event listener
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