PDA

View Full Version : EVAL to apply text variables



davec
July 19th, 2003, 04:19 PM
Hi,

I have a clip containing 8 MCs, named id1, id2 etc, each of which contain a dynamic text field with the variable thisNo. I want to run a loop that inserts each digit from a randomly generated number into each of these MCs

PatID is the random number, IDLength is it's character length.

for (i=1; i<(IDLength+1); i++) {
thisNo = PatID.substr(-i,1);
eval("id"+i).iconNo = thisNo;
}

...but it don't work.

Help!

eyezberg
July 19th, 2003, 04:37 PM
you're mixing numbers and strings here,
if PatID is a rand N°, you shouldn't be using string methods on it,
and IDLength is used in your loop, but where is it assigned the value?? (IDLength=PatID._length)? you don't even need that, if you want to use the string methods, try i<PatID.toString._length.. something like that..

eyezberg
July 19th, 2003, 04:44 PM
Here's a quick'n'dirty fla..

davec
July 19th, 2003, 05:21 PM
:) Thanks Joe, you're a star!

(I was converting the random number to a string first BTW.)

Cheers,

Dave

BoundlessVision
July 19th, 2003, 06:41 PM
This thread also helped me out.
Thankx.

:thumb:

eyezberg
July 19th, 2003, 06:58 PM
cheers then, m8, glad to help

davec
July 20th, 2003, 07:08 AM
Originally posted by eyezberg
Here's a quick'n'dirty fla..

One question though - you used

_root["id"+i].iconNo = thisNo;

Although my clips were on the same level, they weren't on the root as per your example. I had to move the target MCs up a level as this wouldn't work, but _parent would.

Why is that?

Thanks,

Dave