TLFTextfield blocking “ENTER” Keyboard event

Probably my last post about TLFTextfied for a little while. This is going to be a quick one and was actually found by my colleague Will Adams. Also he found the solution somewhere else on the web but I can’t find it anymore so I thought it would be good to post it here too.

So here is the problem, if you use TLFTexfields as input fields for your form and you want to listen for the user pressing the “ENTER” key to submit the form, if at that moment the focus is on the input field, you won’t be able to listen for it. So normally, you would put the Keyboard event listener on the stage so that it doesn’t matter which textfield the user is on, if he presses “ENTER”, it will submit the form. Turns out that for some reasons, TLFTextfield will block that event from firing. Funny thing, is that it doesn’t block other key press events from firing just the “ENTER” (or “RETURN”).

Now for the quick fix:

_tlfTextfield.getChildAt(1).addEventListener(KeyboardEvent.KEY_UP, _onKeyPressed);

So you will have to add this to every of your textfields, which is a bit annoying, but it will make it work. I don’t know how the guy that found this found it, but I’m sure glad he did.


  1. #1 by zh - May 24th, 2011 at 11:26

    Try this:
    var inputManagerConfiguration:Configuration = Configuration(TextFlow.defaultConfiguration).clone();
    inputManagerConfiguration.manageEnterKey = false;
    var flow:TextFlow = new TextFlow(inputManagerConfiguration);

    But if you want to make real single line input fields – you should make one more thing: manage pasting of multiline text. And this problem is much bigger ;)

  2. #2 by - May 24th, 2011 at 16:49

    Ok that works too, but usually I don’t want to use TextFlow or InputManager, I just want to use a textfield hence TLFTextfield.

(will not be published)
Subscribe to comments feed
  1. No trackbacks yet.

Parse error: syntax error, unexpected ';' in /homepages/25/d169645162/htdocs/wp-content/themes/fusion/footer.php on line 13