PDA

View Full Version : Use variable to reference static component name ?


ashar
03-30-2005, 06:46 PM
Without going into all the details, I just want to refer to a
static component name by using a variable....

I have several components in a MC,
mc1.txt_BODY
mc1.cb_BODY

mc1.txt_WEIGHT
mc1.cb_WEIGHT
etc....

I want to be able to reference those components by using
the value I have in a variable called TITLE which will have
a value i.e. "BODY"

mc1.txt_[TITLE].text = "..." //DOESN'T WORK

I tried putting the entire component name in a string and referencing it...

component = ".txt_" + TITLE;

mc1.[component].text = "....." //doesnt work
mc1[component].text = "...." //doesn'twork

Any help ?

ashar
03-30-2005, 07:13 PM
Without going into all the details, I just want to refer to a
static component name by using a variable....

I have several components in a MC,
mc1.txt_BODY
mc1.cb_BODY

mc1.txt_WEIGHT
mc1.cb_WEIGHT
etc....

I want to be able to reference those components by using
the value I have in a variable called TITLE which will have
a value i.e. "BODY"

mc1.txt_[TITLE].text = "..." //DOESN'T WORK

I tried putting the entire component name in a string and referencing it...

component = ".txt_" + TITLE;

mc1.[component].text = "....." //doesnt work
mc1[component].text = "...." //doesn'twork

Any help ?

tg
03-30-2005, 11:44 PM
try:


mc1["txt_"+varName]="...";

ashar
03-31-2005, 03:26 PM
No that doesn't work either, tried it,
but did get the answer on Macromedia's forum.

variablename = "mc1.txt_" + TITLE;

eval(variablename).text = "this text"; // works