FLEX4实践—DropDownList与ComboBox

针对FLEX3中ComboBox的用法,在FLEX4中用法有区别需将s改为mx:
<s:DropDownList dataProvider="{provider}" labelField="label"/>

<mx:ComboBox dataProvider="{provider}" labelField="label"/>

另外需要注意的两点有:
1)DropDownList的DataProvider不能是Array类型的
2)DropDownList默认显示时与ComboBox不一样,需要手动指定 selectedIndex的值
下面给出一段示例:
<?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" creationComplete="init()">    
         
    <fx:Declarations>    
        <!-- Place non-visual elements (e.g., services, value objects) here -->    
        <fx:Array id="arr">    
            <fx:Object dataField="宋体"  headerText="宋体"/>    
            <fx:Object dataField="楷体"  headerText="楷体"/>    
            <fx:Object dataField="黑体" headerText="黑体"/>    
        </fx:Array>    
        <s:ArrayList id="arr1">    
            <fx:Object dataField="宋体"  headerText="宋体"/>    
            <fx:Object dataField="楷体"  headerText="楷体"/>    
            <fx:Object dataField="黑体" headerText="黑体"/>    
        </s:ArrayList>    
    </fx:Declarations>    
    <s:Panel x="448" y="159" width="250" height="200">    
        <mx:ComboBox x="73" y="10" dataProvider="{arr}" labelField="headerText" selectedIndex="0"/>    
        <s:DropDownList x="73" y="50" dataProvider="{arr1}" labelField="headerText" selectedIndex="0"/>    
    </s:Panel>    
</s:Application>

你可能感兴趣的:(combobox)