
转载请保持文章完整性!
本文链接地址:http://blog.desizen.com/4lone/401.html
主页:joel's blog
这个例子进行的是UI Controls:Buttons:PopUpButton
简介:
The PopUpButton control adds a flexible pop-up control interface to a Button control. It contains a main button and a secondary button, called the pop-up button, which pops up any UIComponent object when a user clicks the pop-up button.
例子:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" horizontalAlign="center" backgroundGradientColors="[0x000000,0x323232]" paddingTop="0" viewSourceURL="srcview/index.html"> <!--这个例子实现的是弹出式下拉菜单,但是这个PopUpButton不同于ComboBox,PopUpButton 控件可将灵活的弹出式控件接口添加到 Button 控件。 它包含一个主按钮和一个辅助按钮,后者称为弹出按钮,用于用户单击此弹出按钮时弹出任何 UIComponent 对象。 PopUpButton 控件的表面可包含一个文本标签、一个图标,或者两者都包含。当用户单击 PopUpButton 控件的主要部分时,此控件将调度 click 事件。 PopUpButton 控件的一个常见用法是,使弹出式按钮打开可更改主按钮的函数和标签的 List 控件或 Menu 控件。--> <mx:Script> <![CDATA[ import mx.controls.*; import mx.events.*; import mx.controls.Alert; private var myMenu:Menu; // Initialize the Menu control, and specify it as the pop up object // of the PopUpButton control. private function initMenu():void { myMenu = new Menu(); var dp:Object = [{label: "New Folder"}, {label: "Sent Items"}, {label: "Inbox"}]; //定义数组 myMenu.dataProvider = dp;//赋值引用 myMenu.selectedIndex = 0; myMenu.addEventListener("itemClick", itemClickHandler);//添加监听 popB.popUp = myMenu; popB.label = "Put in: " + myMenu.dataProvider[myMenu.selectedIndex].label; } // Define the event listener for the Menu control's itemClick event. private function itemClickHandler(event:MenuEvent):void { var label:String = event.item.label; popTypeB.text=String("Moved to " + label); popB.label = "Put in: " + label; popB.close(); myMenu.selectedIndex = event.index; } ]]> </mx:Script> <mx:Panel title="PopUpButton Control" layout="vertical" color="0xffffff" borderAlpha="0.15" paddingTop="10" paddingRight="10" paddingBottom="10" paddingLeft="10" horizontalAlign="center"> <mx:Label width="100%" color="0x323232" text="Button label contains the name of the last selected menu item." /> <mx:PopUpButton id="popB" label="Edit" creationComplete="initMenu();" width="140" color="0x323232" click="{Alert.show('Action: ' + popB.label);}" /> <mx:Spacer height="65" />//这个查看手册说是分配空间用的,可是我没有加这个东西的时候也是可以有空间被定位的 <mx:TextInput id="popTypeB" color="0x323232" text="...waiting" /> </mx:Panel> </mx:Application>
标签:FLEX, PopUpButton, TourDeFlex, 例子
