# Constructing the name of a movie instance

**URL:** <https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439>\
**Category:** flash\
**Created:** [July 22, 2004, 2:02pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439 "2004-07-22T14:02:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![iqlabs](https://avatars.discourse-cdn.com/v4/letter/i/54ee81/32.png) [@iqlabs](https://forum.kirupa.com/u/iqlabs)\
**Post date:** [July 22, 2004, 2:02pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/1 "2004-07-22T14:02:15Z")

</div>

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) {  
play();  
}  
}  
Is the above loop correct?  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 2:10pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/2 "2004-07-22T14:10:48Z")

</div>

This is done using associative array referencing:

parentObject[expression]

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.

```auto

  for(i=0;i<6;i++){
  mc = this["movieclipname"+i];
  // now mc is a reference to movieclipnameN, where N is the loop iterator i.
  trace(mc);
  }
  

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 2:11pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/3 "2004-07-22T14:11:47Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 2:13pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/4 "2004-07-22T14:13:03Z")

</div>

you beat me to it voets 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 2:27pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/5 "2004-07-22T14:27:18Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 2:28pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/6 "2004-07-22T14:28:03Z")

</div>

Thanks all of you!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 4:38pm UTC](https://forum.kirupa.com/t/constructing-the-name-of-a-movie-instance/58439/7 "2004-07-22T16:38:32Z")

</div>

Anytime 🙂
