popupmenubutton.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--http://www.javaeye.com/topic/210348-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" layout="absolute">
<mx:Style>
Application{
fontSize:12;
backgroundGradientColors: #c0c0c0, #c0c0c0;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.MenuEvent;
private var mXML:XMLList =
<>
<node label="文件">
<node label="新建画板" data="new"/>
<node label="清除画板" data="clear" enabled="false"/>
<node label="退出系统" data="logout"/>
</node>
<node label="工具"/>
<node label="帮助">
<node label="帮助" data="help"/>
<node label="关于作者" data="about"/>
</node>
</>;
private function initApp():void {
popBtn.dataProvider = mXML; //弹出菜单的数据源
popBtn.addEventListener(MenuEvent.ITEM_CLICK,clickHandler);
}
private function clickHandler(evt:MenuEvent):void{
Alert.show("选择菜单:"+evt.label+":菜单序号:"+evt.index);
}
]]>
</mx:Script>
<mx:PopUpMenuButton id="popBtn" labelField="@label" width="135" x="23" y="23"/>
</mx:Application>