Flex DropDownList控件功能 (
Flex DropDownList控件功能 (2010-07-31 22:16)
分类:
Flex组件
1 DropDownList控件概述DropDownList 控件包含下拉列表,用户可从中选择单个值。其功能与 HTML 中 SELECT 表单元素的功能非常相似。 DropDownList 控件由锚点按钮、提示区域和下拉列表组成,使用锚点按钮可打开和关闭下拉列表。提示区域显示一个提示 String,或者显示下拉列表中的选定项目。 打开下拉列表时:
[1]参考文献:Adobe官方参考文档: http://help.adobe.com/zh_CN/AS3LCR/Flex_4.0/spark/components/DropDownList.html#eventSummary 2 DropDownList控件常用属性和方法
[2]可参考 Flex Gumbo中如何通过itemRenderer属性,在DropDownList中显示图片http://blog.minidx.com/2009/08/13/2832.html 3 DropDownList控件的基本用法3.1 定义DropDownList的数据源1.DataProvider为DropDownList提供下拉菜单的数据,其可以是ArrayCollection类型的。 在As3.0代码中定义一个数据源,代码如下: public var myDP:ArrayCollection = new ArrayCollection( [ {product:"Flex",price:100}, {product:"Air",price:200}, {product:"Catalyst",price:300}, {product:"FlashBuilder",price:400} ]); 3.2 在Lable标签中显示在下拉列表中选中的数据1.在MXML代码中定义一个DropDownListc控件并且同时定义Lable标签用于显示被选择的数据。 代码如下: <!-- Text components used to display current selection and price --> <s:Label id="currSel" text="产品名 =" x="86" y="119"/> <s:Label id="currPrc" text="价格 = $" x="85" y="219"/> <!-- DropDownList will call the updateSelection function when the selectionChanged event is dispatched --> <s:DropDownList id="myDDL" width="200" dataProvider="{myDP}" labelField="product" change="updateSelection(event);" x="241" y="72" prompt="请选择"/> 2.定义了一个change事件如果在下拉菜单中选择了任何一项,则会启动updateSelection函数其会在Lable中显示选择的内容 updateSelection函数的定义如下: privatefunction updateSelection(e:IndexChangeEvent):void { currSel.text = "产品名 = " + myDDL.selectedItem.product; currPrc.text = "价格 = $" + myDDL.selectedItem.price; }
3.3 对requireSelection属性与
|