开发者

How can I catch both edit and selection events on an editable combo box?

开发者 https://www.devze.com 2023-02-10 07:01 出处:网络
I have an editable mx:Combobox. I want to catch two events: 开发者_如何学编程 When a user enters some text, or edits some text.

I have an editable mx:Combobox. I want to catch two events:

    开发者_如何学编程
  1. When a user enters some text, or edits some text.

  2. When a user changes the selection (selects an item from the combo box).

Is it possible? I have been using change event, but it is fired in both cases and I can't differentiate it. Is there a better way of doing this?


Use change event for selected item, use keyUp event for text editing (note hitting Shift+Key fires keyUp twice). Change will be fired for both, but just check if the selectedItem is null to get around this. Also, editable comboBox is not available in Flex 4, so if your thinking of moving to Flex 4 soon, keep this in mind:

            private var ac:ArrayCollection;

            private function onInit():void{

                ac = new ArrayCollection([{name:"john"}, 
                    {name:"Stephen"}]);
                myCombo.dataProvider = ac;
                myCombo.labelField = "name";
            }

            private function onComboChange(event:Event):void{
                if(event.target.selectedItem != null){
                    trace("Item Selected: " + event.target.selectedLabel);
                }
            }

            private function onKeyUp(event:Event):void{
                trace(event.target.text);
            }

    <mx:ComboBox id="myCombo" x="50" y="10" editable="true" change="onComboChange(event)"
                 keyUp="onKeyUp(event)"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号