Search code examples
actionscript-3flashcomboboxtextinput

AS3/Flash: combobox and textinput interaction


I'd like to know if it's possible (AS3/Flash CS5):

  • To reset a combobox to it's prompt state when focusing (clicking) in a textinput field.

  • To empty a textinput when a value is selected in the combobox.

Thanks in advance.

UPDATE:

Many thanks Kieran. I prefer

myComboBox.selectedIndex=0;

than

myComboBox.selectedItem=myComboBox.prompt; 

Due to the index.

Is there any situation where the second one could be more useful?


Solution

  • You could just add a listener for each of scenario. Something like this:

    import flash.events.MouseEvent;
    
    inputText_txt.addEventListener(MouseEvent.CLICK, clearComboBox);
    comboBox.addEventListener(Event.CHANGE, clearTextBox);
    
    function clearComboBox(event:MouseEvent):void
    {
        comboBox.selectedItem = -1; 
    }
    
    function clearTextBox(e:Event):void
    {
        inputText_txt.text = ""; 
    }