I have a series of dynamically created text fields that form a grid and I want people to be able to auto tab through each field in the grid. I want them to be able to enter in 1 character and then have the focus move to the next field in the grid.
All of the TextFields are named “inputBox” with an ID number added to the end using the name property of the TextField class. So they are named as follows inputBox0, inputBox1, inputBox2, etc.
Now for the code I am using to change focus to the next textfield:
stage.addEventListener(KeyBoardEvent.KEY_UP, checkTextField);
function checkTextField(e:KeyboardEvent):void{
var instanceName = e.target.name;
if(e.target.length == e.target.maxChars){
stage.focus = this["inputBox"+(Number(instanceName.substring(8))+1)];
}
}
The part that is giving me the issue is this: this[“inputBox”+(Number(instanceName.substring(8))+1)];
I am not sure how to dynamically reference the next text field because I have tried every variation I can think of and this line is always undefined.
Any insight would be greatly appreciated.
Thanks in advance!