Groups | Blog | Home
all groups > flash (alternate) > january 2005 >

flash (alternate) : Dynamic Text Value???



cowiefr NO[at]SPAM yahoo.com
1/24/2005 3:13:34 PM
Hi all,

I'm stumped by the following code:

for(i=0; i<100; i++) {
tellTarget ("sq"+(i+1))
{numval = i};
trace(i+1);
}

I have 100 instances of a movieclip named "sq1...100" each with a
dynamic text box with a variable named "numval". The code above traces
1 to 100 but the movieclip.dynamictext for each is BLANK!!. If I
replace {numval = i} with {numval = 30) they all have a thirty in them.
If I use {numval = "x") they all have an x in them.
Please help.

Fain
Jeckyl
1/25/2005 1:20:23 AM
for(i=0; i<100; i++) {
tellTarget ("sq"+(i+1))
{numval = i};
trace(i+1);
}

that is going to copy the value of 'i' in your sq1 to variable 'numval' in
sq1 etc .. it won't even look at the value of 'i' in your loop, because of
the tellTarget.

if the above code was in a function , and you used

for (var i=0; i<100; i++) {
....
}

then it would work, as local variable are found first regardless of the
tellTarget saying to look elsewhere.
--
All the best,
Jeckyl

cowiefr NO[at]SPAM yahoo.com
1/26/2005 3:19:27 PM
Thanks guys. I got it working.
JP
1/26/2005 5:39:37 PM
Try changing it to:

for(i=0; i<100; i++) {
eval("sq"+(i+1)).numval = i;
}

or, if the i+1 bit misbehaves,

for(i=1; i<=100; i++) {
eval("sq"+i).numval = i-1;
}

not the neatest thing ever, but I use it loads!
-JP
http://www.maths-pgce.co.uk/

AddThis Social Bookmark Button
View Other Months
January 2005
February 2005