设置comboBox控件的dataProvider属性,可以为其设置其值,例如:
<mx:ComboBox id="typeTime" dataProvider="{type}"/>
<script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public static var type:ArrayCollection= new ArrayCollection([{label:"month", data:1},{label:"year", data:2}]);
]]>
</script>
如果想要获取到dataProvider中设置数组的value值,可以使用comboBox的selectItem属性来获取,例如:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:ComboBox id="timeType" dataProvider="{type}" change="showData()"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public static var type:ArrayCollection= new ArrayCollection([{label:"month", data:1},{label:"year", data:2}]);
public function showData():void
{
trace(timeType.selectedItem.data);
}
]]>
</mx:Script>
</mx:Application>