Hi everyone,
I am trying to create a crossword puzzle made up of text fields, one for each letter. I am pretty much done, but there is one problem I can’t get a handle on. I hope someone brilliant can help:
The Problem:
The user has already typed a letter into TextFied “XY” and then clicks back into that same TextField (maxChars=1, btw.) to write over that letter (or not). I want the letter to stay until a new letter is typed, and definitely, if the user decides not to provide a new letter.
No problem, works 90 percent of the time. But sometimes --I find oddly enough especially with “S” and “D”, but not exclusively-- **the letter disappears and stays gone, even when you leave the TextField. **The Only way to bring it back is to go back into the Textfield and use the Arrow keys to move the courser to a position before the letter. Very Ugly!
This problem is triggered by clicking into the box as well as by the “stage.focus=” method. I already tried the setSelection- no succes, I also tried making the font smaller, - give it breathing room, so to speak- , also fruitless. Does any one have any ideas how that effect could be avoided with certainty? Here is my code for reference:
//my letterbox class
var inputFormat:TextFormat = new TextFormat ();
var initCharacter:String="?";
inputFormat.font = "Arial";
inputFormat.size=14;
inputFormat.color=0x000000;
inputFormat.bold=true;
inputFormat.align="center";
box.type=TextFieldType.INPUT;
box.x=column * lbWidth + gridOffsetX;
box.y=row * lbHeight + gridOffsetY;
box.width=20;
box.maxChars=1;
box.defaultTextFormat=inputFormat;
box.text=initCharacter;
box.addEventListener(FocusEvent.FOCUS_IN, onFocus);
box.addEventListener(FocusEvent.FOCUS_OUT,onFocusOut);
function onFocus(event:FocusEvent):void {
if (box.text==initCharacter) {
box.text="";
}else{
event.target.setSelection(0,0);
}
}
//in another class, the crosswordpuzzle's main class
function userInput(e:TextEvent):void {
var activeField=e.target;
e.preventDefault();
var Caps:String=e.text.toUpperCase();
activeField.text=Caps;
}
Thank you in advance for looking at this.