Constructing the name of a movie instance

I have a number of instances of the same movie in a frame. I have named all
this instances using the form : movieclipname1,movieclipname2…movieclipnameN
I want to control everyone of them so i have to reference everyone of them using it’s own name .
Is it possible to use a loop where I will constructing the name of each movie ?
for example:
for (i=1; i++) {
with (movieclipname+1) {
Is the above loop correct?

This is done using associative array referencing:


The expression inside the brackets is evaluated first, and the result is used as the name of the property or object to retrieve . This is very useful in loops because the loop variable can be used in the brackets to retrieve a movieclip from a serie, as in your situation. Generally, a reference is stored in another short-named variable, mc here, so that the whole process of evaluating the brackets and using it as the name of the property or object can be avoided. This is done once and a reference is stored in mc, so that mc can be used instead of executing the relatively slow associative array referencing each time.

  mc = this["movieclipname"+i];
  // now mc is a reference to movieclipnameN, where N is the loop iterator i.

no mate the above for loop is not correct.

Given that totalClips is already declared and has a value. Also you clips are held within the ‘clipHolder’ mc.

var i;
for(i = 0; i<totalClips; i++)//
     clipHolder["movieclipname" + i].play();

you beat me to it voets :wink:

Thanks all of you!

Anytime :slight_smile: