Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : how to construct the name of an instance in actionscript


SPGAnne
8/27/2006 9:41:35 PM
Sorry for being such a dim bulb newbie, but I know there has to be a way to do
this, but I can't seem to get it right. I have a bunch of text items I have
put in a movie clip, each having a name like myText1_txt, myText2_txt etc. I
want to create a function that sets each field to some value where I would call
setValue(fieldNum:String,value:Number). Where fieldNum would be 1,2, 3 etc. In
the function I tried the following, but it doesn't seem to work.

var myText:TextField;
myText._name= "myText" + fieldNum + "_txt";
myText.text = value;

Alas, myText1._txt, myText2._txt etc. remain undefined.

What am I doing wrong?


NSurveyor
8/27/2006 9:51:16 PM
You can use eval or the array access operator. For example, if your movieclip is my_mc, you would use:

SPGAnne
8/28/2006 1:48:25 AM
AddThis Social Bookmark Button