Flex4 how to select a menu item in menu bar
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.
<?xml version="1.0" encoding="utf-8"?>
<s:layout>
<s:BasicLayout />
&l开发者_运维知识库t;/s:layout>
<fx:Script>
<![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);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XMLList id="menuXML">
<fx:menuitem label="File">
<fx:menuitem label="Open" data="open"/>
<fx:menuitem label="Exit" data="exit"/>
</fx:menuitem>
<fx:menuitem label="View">
<fx:menuitem label="Map" type="check" data="map"/>
<fx:menuitem label="Flights" type="check" data="flights"/>
<fx:menuitem label="Altitude Graph" type="check" data="altitude"/>
</fx:menuitem>
</fx:XMLList>
</fx:Declarations>
<s:controlBarContent>
<mx:MenuBar id="appMenu"
labelField="@label"
showRoot="true"
dataProvider="{menuXML}"
itemClick="appMenu_itemClickHandler(event)"/>
</s:controlBarContent>
Ok I found this post which pretty much does what I want.
Programatically enable/disable menuBar buttons in Flex 4
精彩评论