Actionscript Question
- lapis
-
lapis
- Member since: Aug. 11, 2004
- Offline.
-
- Forum Stats
- Member
- Level 26
- Blank Slate
I tried finding an answer using the Flash MX help, but I couldn't find it. I'll illustrate my question with an example:
Let's say I've got 10 text fields, named t0.....t9. Now I want to change the current texts of all the 10 text fields to "blah".
I could do it the easy way:
t0.text = "blah";
...
t9.text = "blah";
But that's too much typing, so I'd like to use a for-statement.
for(j=0;j<10;j++){
tellTarget("t"+j) {
this.text = "blah";
}
}
But that doesn't work. And neither does this:
for(j=0;j<10;j++) {
setProperty ("t"+j, text,"blah");
}
And I can't use dot-notation like, for example:
for(j=0;j<10;j++){
("t"+j).text = "blah";
}
I'm not that good at programming, so maybe you could help me out?
Thanks for reading.
- Deathcon7
-
Deathcon7
- Member since: Oct. 1, 2003
- Offline.
-
- Forum Stats
- Member
- Level 21
- Writer
It's actually much simple then what you're doing. All you have to do is make the text fields dynamic text fields controlled by variables v0-v9. Then you would use a for but like this:
for(i=0;i<10;i++){
eval("_root.v"+i)="blah";
}
See? Where v0-v9 are variables located on the main timeline. BTW, i know you'll be curious, but the eval function just turns a string into a referance.
- lapis
-
lapis
- Member since: Aug. 11, 2004
- Offline.
-
- Forum Stats
- Member
- Level 26
- Blank Slate
At 9/7/04 11:56 AM, Deathcon7 wrote: It's actually much simple then what you're doing. All you have to do is make the text fields dynamic text fields controlled by variables v0-v9. Then you would use a for but like this:
for(i=0;i<10;i++){
eval("_root.v"+i)="blah";
}
See? Where v0-v9 are variables located on the main timeline. BTW, i know you'll be curious, but the eval function just turns a string into a referance.
Hey thanks man! I didn't even know the "eval" function :(
I need to work a lot on my programming. But that's at least one problem solved.

