<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.*;
import mx.events.*;
private var myMenu:Menu;
// 初始化弹出按钮菜单
private function initMenu():void {
myMenu = new Menu();
var dp:Object = [{label: "目录 1"}, {label: "目录 2"}, {label: "目录 3"}];
myMenu.dataProvider = dp;
myMenu.selectedIndex = 0;
myMenu.addEventListener("itemClick", itemClickHandler);
popB.popUp = myMenu;
}
// 对菜单控件的itemClick事件的监听程序
private function itemClickHandler(event:MenuEvent):void {
var label:String = event.item.label;
popTypeB.text=String("所选菜单 " + label);
popB.label=label;
popB.close();
myMenu.selectedIndex = event.index;
}
]]>
</mx:Script>
<mx:Panel title="弹出按钮示例" height="75%" width="75%"
paddingTop="10" paddingBottom="10" paddingRight="10" paddingLeft="10">
<mx:PopUpButton id="popB" label="点击弹出按钮" creationComplete="initMenu();" width="135"/>
<mx:Spacer height="80"/>
<mx:TextArea height="28" id="popTypeB"/>
</mx:Panel>
</mx:Application>
标签: