Targeting woes

It seems like a simple problem. I have a MovieClip on the stage and I want to target it. After that things get more unusual. Without going into to much detail I am essentially trying to target the mc using a variable that has stored part of the name of the mc I am targeting. Take a look at the code below and hopefully you will understand what I am trying to do, and perhaps even better why it doesn’t work.

The instance names of the MovieClips on my stage are box_1 and box_2. What I am trying to do is store the numerical part of that instance name in a variable, so that I can increment it over time and use the new name to refer to a seperate MovieClip named box_2. This is a very simplified example of what I actually want to accomplish but it should give the general idea.

Thanks in advance for any help.


var boxNumber:Number = 1;

var boxName:String = ('box_' + boxNumber);

trace(boxName);


boxName.x = 500;

//this.box_1.x = 500;

if (box_1.x == 500)
{
	boxNumber + 1;
	boxName.x = 400;
	trace(boxName);
};