Search code examples
apache-flexbuttonclickenterflex-spark

Spark Button - why doesn't pressing the enter key fire click event?


I'm a little confused as to why this isn't the default behaviour?

So, how do I detect the enter key being pressed on my button and fire the click event handler? (For example on a TextInput field there is an 'enter' event)

Thanks


Solution

  • EDIT: Ignore everything I posted before.

    You can use the keyDown event on the spark button and create an event handler using KeyboardEvent.

            <s:Button label="Submit" keyDown="enter_pressed(event)" id="submit" click="submit_clickHandler(event)"/>
    
            protected function enter_pressed(event:KeyboardEvent):void { 
                if(event.charCode == Keyboard.ENTER){
                    submit.dispatchEvent(new MouseEvent(MouseEvent.CLICK)); 
                }
            }