title: Flex4 how to select a menu item in menu bar
body: <p>I have a menu bar in a spark Panel, I want to select one of the menu items by using Actionscript I don't know how to target one of the items. Here is an extract from my component code.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;s:layout&gt;
      &lt;s:BasicLayout /&gt;
  &lt;/s:layout&gt;
  &lt;fx:Script&gt;
      &lt;![CDATA[
          import events.CustomMenuEvent;
  
          import mx.collections.ArrayCollection;
          import mx.events.MenuEvent;
  
          public function update(id:String):void
          {
              // This is where I would call the menu to update the button
                              // from its mediator.
          }
  
          protected function appMenu_itemClickHandler(event:MenuEvent):void
          {
              var data:String = event.item.@data;
              var menuEvent:CustomMenuEvent = new CustomMenuEvent(CustomMenuEvent.ITEM_CLICKED);
              menuEvent.toggled = Boolean(event.item.@toggled == "true");
              menuEvent.data = data;
              dispatchEvent(menuEvent);
          }
      ]]&gt;
  &lt;/fx:Script&gt;
  
  &lt;fx:Declarations&gt;
      &lt;fx:XMLList id="menuXML"&gt;
          &lt;fx:menuitem label="File"&gt;
              &lt;fx:menuitem label="Open" data="open"/&gt;
              &lt;fx:menuitem label="Exit" data="exit"/&gt;
          &lt;/fx:menuitem&gt;
          &lt;fx:menuitem label="View"&gt;
              &lt;fx:menuitem label="Map" type="check" data="map"/&gt;
              &lt;fx:menuitem label="Flights" type="check" data="flights"/&gt;
              &lt;fx:menuitem label="Altitude Graph" type="check" data="altitude"/&gt;
          &lt;/fx:menuitem&gt;
      &lt;/fx:XMLList&gt;
  &lt;/fx:Declarations&gt;
  
  &lt;s:controlBarContent&gt;
      &lt;mx:MenuBar id="appMenu" 
                  labelField="@label" 
                  showRoot="true"
                  dataProvider="{menuXML}"
                  itemClick="appMenu_itemClickHandler(event)"/&gt;
  &lt;/s:controlBarContent&gt;
  </code></pre>
  
  <p></p>