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?
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?