menuBar有几个比较重要的属性labelField,dataProvider,itemClick。labelField指定界面显示的是数据源当中的哪个元素,dataProvider指数据源,通常用一个xmlListCollection,itemClick触发某个函数,比较重要的是可以使用其元素某个名字进行函数调用,比如
<?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.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" action="itemAction"/>
<menuitem label="MenuItem 1-B" data="1B" action="itemAction"/>
</menuitem>
<menuitem label="Menu2" data="top">
<menuitem label="MenuItem 2-A" type="check" data="2A" action="itemAction"/>
<menuitem type="separator" action="itemAction"/>
<menuitem label="MenuItem 2-B" action="itemAction" >
<menuitem label="SubMenuItem 3-A" type="radio"
groupName="one" data="3A" action="itemAction"/>
<menuitem label="SubMenuItem 3-B" type="radio"
groupName="one" data="3B" action="itemAction"/>
</menuitem>
</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");
}
}
//itemClickAction
private function itemAction():void{
Alert.show("itemclickaction");
}
]]>
</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="this[event.item.@action]()"
dataProvider="{menuBarCollection}" />
</mx:Panel>
</mx:Application>