Call variable by name similar to getChildByName? Is there a way?

Hello,

I have a several functions that I can compact into 1 function via a for loop if only I can find a way to call the variable by name.

For example:

This is what I want to accomplish: (However I do not have the slightest clue as to how to go about doing the below…)


var test1:String = "testing 1";
var test2:String = "testing 2";
var Complete1:String = test+1;
var Complete2:String = test+2; 
trace(Complete1); // outputs "testing 1"
trace(Complete2); // outputs "testing 2"

I am able to do something similar to the above when using objects using methods such as: (I know not efficient, but its just an example to show what I am trying to accomplish.)

var test1:String = "testing 1";
var test2:String = "testing 2";
var A:int = 1;
var B:int = 2;
getChildByName("test"+A) //Grabs child test1
getChildByName("test"+B) //Grabs child test2

Is something like this possible or no?


```actionscript
var test1:String = "testing 1";
var test2:String = "testing 2";

trace(this['test'+'1']);  // outputs "testing 1"