Flex(Flash Builder)中,ComboBox禁止用戶自動編輯的簡易方法

使用的是Flex4,據說Flex3使用的是label


一開始在網上搜索資料,說要使用“皮膚”,作爲一個初學者,不懂~~~


有一個簡單的小技巧

Flex中Combo源碼

*  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
public class ComboBox extends DropDownListBase implements IIMESupport
{
    //--------------------------------------------------------------------------
    //
    //  Skin Parts
    //
    //--------------------------------------------------------------------------   
    /**
     *  Optional skin part that holds the input text or the selectedItem text.
     * 
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart(required="false")]
    public var textInput:TextInput;    //   這裏,使用的是一個輸入框
            
    //--------------------------------------------------------------------------
    //
    //  Class mixins
    //
    //--------------------------------------------------------------------------
            
    /**
     *  @private
     *  Placeholder for mixin by ComboBoxAccImpl.
     */
    mx_internal static var createAccessibilityImplementation:Function;
            
    /**
     *  Constructor.
     * 
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function ComboBox()
    {
        super();
                
        addEventListener(KeyboardEvent.KEY_DOWN, capture_keyDownHandler, true);
        allowCustomSelectedItem = true;
    }

也就是說,可以利用輸入框的editable來限定是否能夠輸入

<!-- 下拉選框中有一個小技巧來禁止用戶手動輸入,也可以使用“皮膚”的方式,但是相對麻煩一些 -->
        <s:ComboBox id="selectUnit" x="117" y="154" width="174" change="comboBoxClick()"
                    dataProvider="{_unitSelectList}" enabled="true" prompt="choose a number"
                    selectedIndex="-1" creationComplete="selectUnit.textInput.editable = false"/>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章