Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems capturing Enter keystroke

Status
Not open for further replies.

clemrock

Programmer
May 20, 2004
118
US
Hello,

I have a curious dilemma in trying to capture the enter keystroke.


Here's what I'm trying to do:


1. Set the focus on a text field when the program loads.
2. When the user enters text and hits the enter button, it fires a function.

Now, the code below is nearly there but when the program loads, and you type in any key EXCEPT THE ENTER KEY, all keystrokes are capured and recorded EXCEPT THE ENTER KEY.

The only way you can cause the enter key to respond is by first physically pointing and clicking your mouse in the text field first and then hitting enter.

Here's the code:
username_txt.focusEnabled = true;
Selection.setFocus(username_txt);


TextField.prototype.onKeyDown = function ()
{
trace( "onKeyDown" );
if( Key.getCode() == Key.ENTER ){ trace( "ENTER PRESSED" ); } /*doesn't work unless you first pointed and clicked your mouse in the textfield */
}
};

TextField.prototype.onKeyUp = function ()
{
trace( "onKeyUp" );
if( Key.getCode() == Key.ENTER ){ trace( "ENTER PRESSED" ); } /*doesn't work unless you first pointed and clicked your mouse in the textfield */
}



Very strange.

Any Ideas?
 
enter does not show up in the flash authoring environment but will fire ok when viewed in a browser
 
Ok - my bad - of course it's not going to work in the authoring environment.

Thanks for your time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top