I am encountering a rather frustrating problem with a chat class I am putting into a game.
Basically this is what is happening:
1) I listen for a KeyboardEvent.KEY_DOWN for the letter “t”. (“t” brings up team chat)
2) That then calls a class to make an input text field visible (Timeline Created).
3) I then stage.focus to that input text.
All works fine except that the letter “t” is appearing in my input text field.
So, I figured it was capturing the KeyboardEvent and inputting “t”, thus I created an event listener to trigger after the input text field is stage.focus’d to clear that input text field by calling inputText.text = “”;
However, it won’t work, instead of clearing it to “” it just leaves the “t”.
I experimented some more and tried to set inputText.text = “CLEAR” after the focus event.
Something strange happens where after all is said and done, the input text field shows “tCLEAR” with the cursor right after t and when I type in more, it pushes the “CLEAR” to the right.
As far as I know, any text field dynamic or input, if you set it to “”, it should clear it. However in this case its not, its just pushing the “” after the t.
Anyway, I have done a lot of searching, but to no avail.
I even have tried clearing to “” after a TextEvent.TEXT_INPUT and even removed the KeyListener after pressing “t”, still no joy.
Any help would be appreciated.
You can add
event.stopImmediatePropogation()in yourKeyboardEvent.KEY_DOWNhandler. Or if this won’t help try usingKeyboardEvent.KEY_UPevent to capture pressed button withevent.stopImmediatePropogation()in its handler.EDIT
Well, I don’t know why it’s important for you to do exactly that way with key down event. But I can suggest this solution:
1) Add
TextEvent.TEXT_INPUTlistener to TextField in your key down handler.2) And in text input handler add
event.preventDefault();and removeTextEvent.TEXT_INPUTlistener.Something like this:
Where
tfis your textField.