Create Menu from Array : Menu Model « Components « Flex






Create Menu from Array

Create Menu from Array
      

<?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 var myMenu:Menu;

        private function createAndShow2():void {
            myMenu = Menu.createMenu(null, menuData, true);
            myMenu.addEventListener(MenuEvent.ITEM_CLICK, menuShowInfo2);
            myMenu.addEventListener(MenuEvent.MENU_SHOW, menuShowInfo2);
            myMenu.addEventListener(MenuEvent.ITEM_ROLL_OVER,menuShowInfo2);
            myMenu.addEventListener(MenuEvent.ITEM_ROLL_OUT,menuShowInfo2);
            myMenu.show(225, 10);
        }
        private function menuShowInfo2(event:MenuEvent):void {
            ta1.text="event.type: " + event.type;
            ta1.text+="\nevent.label: " + event.label;
            ta1.text+="\nevent.index: " + event.index;
            if (event.item) {
                ta1.text+="\nItem label: " + event.item.label
                ta1.text+="\nItem selected: " + event.item.toggled;
                ta1.text+= "\ntype: " + event.item.type;
            }
        }
        [Bindable]
        public var menuData:Array = [
            {label: "MenuItem A", children: [
                {label: "SubMenuItem A-1", enabled: false},
                {label: "SubMenuItem A-2", type: "normal"}]},
            {label: "MenuItem B", type: "check", toggled: true},
            {label: "MenuItem C", type: "check", toggled: false},
            {type: "separator"},
            {label: "MenuItem D", children: [
                {label: "SubMenuItem D-1", type: "radio", groupName: "g1"},
                {label: "SubMenuItem D-2", type: "radio", groupName: "g1",toggled: true},
                {label: "SubMenuItem D-3", type: "radio", groupName: "g1"}]}
        ];
      
    </mx:Script>
    <mx:Button x="10" y="35" label="Open Object Popup" click="createAndShow2();" />
    <mx:TextArea x="10" y="70" width="200" height="300" id="ta1" />
</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 MenuBar from XMLListCreate MenuBar from XMLList
9.Create menu from XMLCreate menu from XML
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