Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex 4 detect if user presses enter key

The secnario is simple if the user presses enter while in the password field, I would like to submit the login for for processing.

How can I detect that event from with in the specific text box.

Thanks in advance

like image 991
Craig Mc Avatar asked Sep 09 '10 11:09

Craig Mc


People also ask

How do you check if the Enter key is pressed?

keyCode === 13) { console. log('Enter key pressed') } }); to check if the key with key code 13 is pressed. If it is, then we know the enter key is pressed.

How do you check if the Enter key is pressed in JavaScript?

In plain JavaScript, you can use the EventTarget. addEventListener() method to listen for keyup event. When it occurs, check the keyCode 's value to see if an Enter key is pressed.


2 Answers

You don't need to worry about keyPress events in this case. TextInput conveniently dispatches an enter event when user presses enter.

<mx:TextInput id="passwd" displayAsPassword="true" enter="submit()"/>

Script:

private function submit():void
{
  var pw:String = passwd.text;
  //submit the login here.
}

This is applicable for spark TextInput also.

like image 140
Amarghosh Avatar answered Sep 25 '22 20:09

Amarghosh


keyDown="if (event.keyCode==Keyboard.ENTER){ userRequest.send();}"

like image 34
Craig Mc Avatar answered Sep 24 '22 20:09

Craig Mc