# Dynamic MCs and indexing them

**URL:** <https://forum.kirupa.com/t/dynamic-mcs-and-indexing-them/308670>\
**Category:** flash\
**Created:** [April 28, 2010, 2:24am UTC](https://forum.kirupa.com/t/dynamic-mcs-and-indexing-them/308670 "2010-04-28T02:24:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marquizzo](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@marquizzo](https://forum.kirupa.com/u/marquizzo)\
**Post date:** [April 28, 2010, 2:24am UTC](https://forum.kirupa.com/t/dynamic-mcs-and-indexing-them/308670/1 "2010-04-28T02:24:33Z")

</div>

Hello! I’m having a problem while assigning variables into dynamically-created MovieClips. Here’s a pseudo-code of what I’m trying to achieve.

```php
var myArray:Array = [];

// Create a movieClip for each element in XML.

for each(var tempXML:XML in allXML.details){
   var myMC:MovieClip = new MovieClip();

   myMC.y = myArray.length * 20;
   // Line above easily changes the y value of the MC
   // because the y variable is already declared in the MC class

   myMC.indexNumber = myArray.length;
   // Line above does not pass indexNumber variable into myMC
   // How can I assign new variables into this MC?
   
   this.stage.addChild(myMC);
   myArray.push(myMC);
}

```

I need the movie clips to contain their index values as a variable within them. I’ve tried several approaches, including declaring the variable names within the MC itself, but that doesn’t work either.

I would be very grateful if anyone could help me achieve this, thanks!
