I'm searching the web as well as these forums and all I'm
seeing is that I can add an object that has an onKeyUp() function
to some global MovieClip named "Key". That doesn't help me when I
have 5 text fields on the Stage and only one of them is supposed to
"fire" when Enter is pressed within it. Is there no way to add a
listener to a single text field, as in Java?
Is the common workaround something nasty like add a focus
listener to the field, and when you enter it, add the special
listener to the global Key thing and when you leave the text field,
remove said listener? If that is indeed the case, tell me you can
at least add focus listeners to single fields, and not to some
global "Focus" object...
Any confirmation/correction extremely appreciated.
There is a global "Focus" method - Selection.getFocus(). I
don't understand exactly why that would cause problems for you -
that's a good thing isn't it? you don't need to bother with focus
listeners like you were considering. Using the Key Class(Key is a
class, not a MovieClip) to determine when the Enter key is pressed,
you could check which textfield has focus with
Alternatively, you could put an onChanged event handler on
the textfield and check if (Key.getCode() == Key.ENTER). this will
only work if your text box is multiline as the Enter key won't
trigger an onChanged otherwise.