Dynamically Populate Menus : Menu Model « Components « Flex






Dynamically Populate Menus

Dynamically Populate Menus
      

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp(event)">

    <mx:MenuBar id="menu" dataProvider="{menu_dp}"/>

    <mx:Script>
        
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;

            [Bindable]
            private var menu_dp:ArrayCollection;

            private function initApp(evt:FlexEvent):void {
                var temp:Array = new Array();

                var subNodes:ArrayCollection = new ArrayCollection( [ {label:"New"},
                                                                      {label:"Open"},
                                                                      {label:"Close",enabled:false}
                                                                    ]);
                temp.push({label:"File",children:subNodes});
                temp.push({label:"Source"});

                subNodes = new ArrayCollection( [   {label:"50%", type:"radio", groupName:"one"},
                                                    {label:"100%", type:"radio", groupName:"one",selected:true},
                                                    {label:"150%", type:"radio", groupName:"one"}
                                                ]);
                temp.push({label:"View",children:subNodes});
                menu_dp = new ArrayCollection(temp);
            }
      
    </mx:Script>

</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.Create Menu from ArrayCreate Menu from Array
11.Define XML or XMLList object as a direct child of the Define XML or XMLList object as a direct child of the <mx:MenuBar>
12.Model With MenuModel With Menu