Flex中PopUpButton控件的使用

PopupButton.mxml文件内容如下:

 

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>

<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.Menu;
import mx.events.MenuEvent;

private var myMenu:Menu;

private function initMenu():void
{
myMenu = new Menu();
var object:Object = [{label:"新建文件夹"},{label:"新建文件"},{label:"新建公文包"}];

myMenu.dataProvider = object;//绑定数据源
myMenu.selectedIndex = 0;
myMenu.addEventListener(MenuEvent.ITEM_CLICK,itemClickHandler);//调用菜单项单击事件

popUpButtonId.popUp = myMenu;//指定要弹出的对象
popUpButtonId.label = "Put in:"+myMenu.dataProvider[myMenu.selectedIndex].label;//将选择的菜单项显示在按钮上
}

//菜单单击事件方法
private function itemClickHandler(event:MenuEvent):void
{
var label:String = event.item.label;
tiValue.text = String("Moved to:"+label);
popUpButtonId.label = "显示:"+label;
popUpButtonId.close();//关闭菜单项
myMenu.selectedIndex = event.index;
}

]]>
</fx:Script>

<s:Panel width="75%" height="75%" horizontalCenter="0" title="PopupButton" verticalCenter="0">
<s:VGroup left="10" right="10" top="10" bottom="10">
<s:Label width="100%" color="blue" text="PopupButton的使用"/>

<mx:PopUpButton id="popUpButtonId" width="135" label="==请选择=="
creationComplete="initMenu()"/>

<s:Spacer height="50"/>

<s:TextInput id="tiValue"/>
</s:VGroup>
</s:Panel>

</s:WindowedApplication>

 

你可能感兴趣的:(Flex,PopUpButton)