I am working on an AS3 Flash game that initially takes a input from a barcode scanner. The data that it scans comes in as one long string using tabs to separate the data segments. The scanner acts as a keyboard and inputs the string into a hidden textfield so that I can grab the string and split it apart to get the data.
The input and everything works great. The issue that I am running into is that when the the textfield receives a tab character, instead of inserting the character into the textfield it highlights whatever is in the textfield. Then the next set of characters overwrite what was already in the textfield.
Is there any way around this? Is there some way to make the textfield accept the tab as a literal character? I cannot change the way the barcode delimits the data in the string.
Thanks for any help you can give.
-
(Updated solution)
That is indeed preventabe. You can stop it with following text (assuming Text is the textfield).
Text.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, TextKeyFocusChange); private function TextKeyFocusChange(e:FocusEvent):void { e.preventDefault(); var txt:TextField = TextField(e.currentTarget); txt.appendText("\t"); txt.setSelection(txt.length, txt.length); }
: This almost works. I'm unable to add the "\t" character, but I can enter the unique string "?$". The problem now is that when I .appendText() the cursor remains in front of the added text. The result is the data string followed by a series of ?$.Lillemanden : I've update my solution. I have no problem with \t here, it inserts a tab char.M28 : If the user selected a part of the text, it won't overwrite it.
0 comments:
Post a Comment