Casting Issue

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. These are all created dynamically in a loop and are named as follows inputBox0, inputBox1, inputBox2, etc.

I appear to be running into a bizarre casting issue when tring to access the dynamically created text field. When I try add 1 to the ID number at the end of “inputBox” so that the focus changes to the next box, like as in the following line of code it does not work.

var ipBox:String = “inputBox”+int(instanceName.substring(8))+1;
Resulting Value of ipBox: inputBox1

However, I figured out accidentally that it works when a number is just appended onto the string although it doesn’t yeild the correct result.
var ipBox:String = “inputBox”+instanceName.substring(8)+1;
Resulting Value of ipBox: inputBox01

In either case if when I trace typeOf(ipBox) I get a String, but for some reason the addition in the variable declaration is causing stage.focus = this[ipBox]; to come back undefined.

Here is the function in question:

stage.addEventListener(KeyBoardEvent.KEY_UP, checkTextField);

function checkTextField(e:KeyboardEvent):void{
var instanceName = e.target.name;
var ipBox:String = “inputBox”+int(instanceName.substring(8))+1;
if(e.target.length == e.target.maxChars){
stage.focus = this[ipBox];
}

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!