EVAL to apply text variables

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!

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…

Here’s a quick’n’dirty fla…

:slight_smile: Thanks Joe, you’re a star!

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

Cheers,

Dave

This thread also helped me out.
Thankx.

:thumb:

cheers then, m8, glad to help

*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