I have an editable mx:Combobox. I want to catch two events:
- 开发者_如何学编程
When a user enters some text, or edits some text.
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)"/>
精彩评论