Flex4 下拉框案例

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   minWidth="955" minHeight="600">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			//初始化下拉框的值.注意:名称一定要为:label 此处也可以用自定义的as类.如果要使用后台JAVA类,则将AS类与JAVA实体类绑定 同时在ComBox 设置显示的字段: labelField="XX"
			[Bindable]
			private var datas:ArrayCollection = new ArrayCollection([{label:"选项1"},{label:"选项2"},{label:"选项3"},{label:"选项4"}]);
			
			protected function delItem_clickHandler(event:MouseEvent):void
			{
				datas.removeItemAt(items.selectedIndex);
				items.selectedIndex =0;
				
			}
			
			protected function newItem_clickHandler(event:MouseEvent):void
			{
				var s:String = itemValue.text;
				datas.addItem(s);
				items.selectedIndex = datas.length;
				itemValue.text="";
			}
			
		]]>
	</fx:Script>
	
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<s:Panel width="250" height="200" title="下拉框案例">
		<s:TextInput id="itemValue" x="10" y="75" width="150"/>
		<s:Button id="newItem" x="168" y="75" label="新建项" click="newItem_clickHandler(event)"/>
		<s:ComboBox id="items" x="10" y="34" width="228" dataProvider="{datas}" selectedIndex="0" />
		<s:Button id="delItem" x="168" y="104" label="删除选中" click="delItem_clickHandler(event)"/>
	</s:Panel>
</s:Application>
 

你可能感兴趣的:(flex4)