2011-02-15 81 views
0

我有一個可編輯mx:Combobox。我想捕獲兩個事件:如何捕獲可編輯組合框上的編輯和選擇事件?

  1. 當用戶輸入一些文本或編輯一些文本時。

  2. 當用戶更改選擇(從組合框中選擇一個項目)。

這可能嗎?我一直在使用change event,但它在兩種情況下被解僱,我無法區分它。有沒有更好的方法來做到這一點?

+0

我不認爲有對both.Only不同的事件改變事件你可以做的是,一旦更改事件被觸發,在eventHandler中,你可以比較這些值,編寫一個邏輯來區分這兩個事件。 – Neeraj 2011-02-15 06:41:34

回答

0

使用所選項目的更改事件,使用keyUp事件進行文本編輯(注意按住Shift + Key觸發鍵盤兩次)。更改將被觸發,但只是檢查selectedItem是否爲空來解決這個問題。此外,編輯ComboBox不可用Flex 4中,因此,如果您移動的想法很快Flex 4中,記住這一點:

  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)"/>