PDA

View Full Version : any tips for FOR loops?



kdzines
October 10th, 2003, 07:20 PM
hey,

in my quest to make my code more manageable, i am trying to figure out how to take the following code and put it in a FOR loop



_root.createEmptyMovieClip("holder", 10);
holder._x = 50;
holder._y = 50;

_root.createEmptyMovieClip("holder2", 11);
holder2._x = 50;
holder2._y = 50;

_root.createEmptyMovieClip("holder3", 12);
holder3._x = 50;
holder3._y = 50;

_root.createEmptyMovieClip("holder4", 13);
holder4._x = 50;
holder4._y = 50;


so i get how to do it, but i got problems with the syntax. I made this




this.onEnterFrame = function(){
for (i, i<4,i++){
_root.createEmptyMovieClip("holder"+i, i);
holder[i]._x = 50;
holder[i]._y = 50;
}
}


if someone could take a few mins and write it for me, i would forever understand how to do it.

cheers,

kd

ahmed
October 10th, 2003, 07:26 PM
a) get rid of the onEnterFrame, you don't need it at all, it just hogs the movie

b) it's for ( i=0 ; i<4 ; i++ )

c) it's this["holder"+i], not what you had :)


for (i=0;i<4;i++){
mc = _root.createEmptyMovieClip("holder"+i, i);
_root["holder"+i]._x = 50;
_root["holder"+i]._y = 50;
}

kdzines
October 10th, 2003, 07:37 PM
cool! thanks!

and you were quick! cheers