Apparently this is something that happened in Flex 1.5 by default or was easily settable. It wasn’t too difficult in the Flex 2.x codebase, but I thought I’d post the solution anyways.

Here is the sample app:

<?xml version="1.0"?>
<!– Simple example to demonstrate the MenuBar control. –>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initCollections();">
    <mx:Script>
        <![CDATA[
            import mx.controls.menuClasses.IMenuBarItemRenderer;
            import mx.controls.MenuBar;
            import mx.controls.menuClasses.MenuBarItem;

            import mx.events.MenuEvent;
            import mx.controls.Alert;
            import mx.collections.*;
           

            [Bindable]
            public var menuBarCollection:XMLListCollection;
   
            private var menubarXML:XMLList =
                <>
                    <menuitem label="Menu1" data="top">
                        <menuitem label="MenuItem 1-A" data="1A"/>
                        <menuitem label="MenuItem 1-B" data="1B"/>
                    </menuitem>
                    <menuitem label="Menu2" data="top">
                        <menuitem label="MenuItem 2-A" type="check"  data="2A"/>
                        <menuitem type="separator"/>
                        <menuitem label="MenuItem 2-B" >
                            <menuitem label="SubMenuItem 3-A" type="radio"
                                groupName="one" data="3A"/>
                            <menuitem label="SubMenuItem 3-B" type="radio"
                                groupName="one" data="3B"/>
                        </menuitem>
                    </menuitem>
                    <menuitem label="Menu3" data="top">
                        <menuitem label="MenuItem 3-A" data="3A"/>
                        <menuitem label="MenuItem 3-B" data="3B"/>
                    </menuitem>
                    <menuitem label="Menu4" data="top">
                        <menuitem label="MenuItem 4-A" data="4A"/>
                        <menuitem label="MenuItem 4-B" data="4B"/>
                    </menuitem>                                       
                </>;

            // Event handler to initialize the MenuBar control.
            private function initCollections():void {
                menuBarCollection = new XMLListCollection(menubarXML);
            }

            // Event handler for the MenuBar control’s itemClick event.
            private function menuHandler(event:MenuEvent):void  {
                // Don’t open the Alert for a menu bar item that
                // opens a popup submenu.
                if (event.item.@data != "top") {
                    Alert.show("Label: " + event.item.@label + "\n" +
                        "Data: " + event.item.@data, "Clicked menu item");
                }       
            }
           
            private function onTopSelection(event:MenuEvent):void{
                var mb:MenuBar=event.target as MenuBar;
                var selectedIndex:int=mb.selectedIndex;
   
                for (var i:int=0;i<mb.menuBarItems.length;i++){
                    if(i==selectedIndex){
                        (mb.menuBarItems[i] as MenuBarItem).setStyle("fontWeight","bold");               
                    }
                    else{
                        (mb.menuBarItems[i] as MenuBarItem).setStyle("fontWeight","normal");                           
                    }
                }
            }
           
         ]]>
    </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" itemClick="menuHandler(event);"
            dataProvider="{menuBarCollection}" change="onTopSelection(event)" />
           
    </mx:Panel>
</mx:Application>
 

Browse the source of this example.
Download a zipfile containing the source to this sample.

This movie requires Flash Player 9

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • digg
  • Technorati
  • Reddit
  • del.icio.us
  • Slashdot