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:30 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?


kglad
8/27/2006 11:04:43 PM
try:



tl=this;

textFieldF(1,"text in myText1_txt);

function textFieldF(n,value){
tl["myText"+n+"_txt"].text=value;
kglad
8/27/2006 11:04:43 PM
try:



tl=this;

textFieldF(1,"text in myText1_txt);

function textFieldF(n,value){
tl["myText"+n+"_txt"].text=value;
AddThis Social Bookmark Button