Chat Input - KeyboardEvent help


(John) #1

Hello everyone o/. I’m working on a game and I’m currently trying to implement a chat input field with little to no success. Since the game will be using characters like “ã”, “ç” and “ó” I was forced to implement it outside of FlashPunk, using some of the tools available from the AS library itself.

I’m using an event listener attached to a TextInput object, set to work with a KeyboardEvent.KEY_DOWN event, calling a function to handle the pressed keys and update the text on the TextInput. The TextInput object itself is a property of an Entity I created to render the text as graphic when the user writes something. Bellow follows the event code:

public function ChatInput(){ //other ChatInput configs             sourceText = new TextInput();             sourceText.addEventListener(KeyboardEvent.KEY_DOWN, typeHandle);             sourceText.textField.addEventListener(KeyboardEvent.KEY_DOWN, typeHandle);             …         }                  function typeHandle(event:KeyboardEvent):void{             trace(“entered here”);             doStuff();         }

I added listeners to both the TextInput and its TextField property (read somewhere that the Input had to use some other kind of event? Not sure…), I tested it with a listener only on the TextInput and later on its TextField but it didn’t work either way. I also had them added to the stage AND engine, wondering if that could have been the problem but it was no good, please help D:


(Jacob Albano) #2

I’m afraid I don’t have any insight into this particular problem, but have you tried using Input.keyString? It or its implementation might help you out.


(John) #3

Thanks! I wasn’t aware of that, gonna give it a shot! :smiley:


(John) #4

Hey folks! So I tested the Input.keyString (and the Input.lastKey too) and was able to handle the input text (rather easily, may I add), but I still couldn’t work with characters like ~, etc. Is there any way at all that Flashpunk can handle those? I guess I could add an eventListener to the engine and have Flash manage it, but that would need me to change the project’s structure, and I won’t be doing that unless there’s no option left. Thoughts? Please and thank you.


(Martí Angelats i Ribera) #5

The default font don’t have that character. This means it can’t be rendered.

Try to set a regular font like Arial and test it again.

PD: I hadn’t try it but i’m 100% the fon’t don’t have this charecter. It don’t have accents and it misses a big part of the special charecters (only the most usuals).


(John) #6

I’ve completely overlooked the font in this matter. Gonna try a few others to check, thanks! :smile:


(John) #7

So, I’ve tried changing the font. I’m using a Text object to render it as my entity’s graphic in order for the typed text to appear, but the same problem with unrecognized characters remains. Do I have to change the font elsewhere specifically other than the Text I’m using? If so how/where do I acess this property? Thank you ;D


(Martí Angelats i Ribera) #8

If you change Text.font All the created Text will have that font by default.

If you want to change the font of a single Text, use the font property.

Example:

Text.font = "myFont"; 
/*It sets the default font for the next text (won't effect the ones that are already created)*/

var myText:Text = new Text("String", 0, 0,  options); //creates the text

myText.font = "myAnotherFont"; //Changes the font without change the default one

(John) #9

I had originally set the font for the Text entity to no avail, unfortunatelu :frowning:. I guess I’ll have to treat each character individually with the accents through charAt, also considering the shift key, oh well.