Skip to main content
Inspiring
July 28, 2009
Answered

move MCs with for loop?

  • July 28, 2009
  • 2 replies
  • 409 views

I'm trying to figure out a way to move movie clips with a for loop

I've got 10 dots called dt1-dt10 and I want to be able to set them all to y = 200.

I understand i can set i=1;i<11;i++

like

for(i=1;i<11;i++){

dt+i._y = 200;}

or

for(i=1;i<11;i++){

String("dt"+i)._y = 200;}

but the rest of it is a mess and either doesn't work, or glitches. I have yet to find a for loop help file for moving multiple movie clips.

This topic has been closed for replies.
Correct answer Ned Murphy

If you just want to immediately change the positions of the instances, then using a for loop will work okay, you just need to use the bracket notation [ ] to have strings be interpreted as instance names...

for(i=1;i<11;i++){

     this["dt"+i]._y = 200;

}

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
July 29, 2009

If you just want to immediately change the positions of the instances, then using a for loop will work okay, you just need to use the bracket notation [ ] to have strings be interpreted as instance names...

for(i=1;i<11;i++){

     this["dt"+i]._y = 200;

}

kglad
Community Expert
Community Expert
July 29, 2009

for-loops and while-loops execute from beginning to end before anything is updated on-stage.  so, they can't be used to display animation.

use an enterframe loop or setInterval() loop.