Create MenuBar from XMLList : Menu Model « Components « Flex






Create MenuBar from XMLList

Create MenuBar from XMLList
      

<?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 rollOverHandler(event:MenuEvent):void {
            rollOverTextArea.text = "type: " + event.type + "\n";
            rollOverTextArea.text += "target menuBarIndex: " +event.index + "\n";
        }
      
    </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}" 
                    itemRollOver="rollOverHandler(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.Create a Menu that uses an Array data providerCreate a Menu that uses an Array data provider
2.Use to define the data for the Menu controlUse <mx:XML> to define the data for the Menu control
3.Use XMLListCollection as the data model for MenuBarUse XMLListCollection as the data model for MenuBar
4.Provide Data for MenusProvide Data for Menus
5.Array DataProvider for MenuArray DataProvider for Menu
6.An XML menu data provider with iconsAn XML menu data provider with icons
7.The dataProvider property is the default property of the MenuBar controlThe dataProvider property is the default property of the MenuBar control
8.Create menu from XMLCreate menu from XML
9.Create Menu from ArrayCreate Menu from Array
10.Define XML or XMLList object as a direct child of the Define XML or XMLList object as a direct child of the <mx:MenuBar>
11.Dynamically Populate MenusDynamically Populate Menus
12.Model With MenuModel With Menu