# How to call a Button inside a MovieClip, with names stored in Arrays

**URL:** <https://forum.kirupa.com/t/how-to-call-a-button-inside-a-movieclip-with-names-stored-in-arrays/327572>\
**Category:** flash\
**Created:** [March 10, 2012, 2:13pm UTC](https://forum.kirupa.com/t/how-to-call-a-button-inside-a-movieclip-with-names-stored-in-arrays/327572 "2012-03-10T14:13:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![megalord](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@megalord](https://forum.kirupa.com/u/megalord)\
**Post date:** [March 10, 2012, 2:13pm UTC](https://forum.kirupa.com/t/how-to-call-a-button-inside-a-movieclip-with-names-stored-in-arrays/327572/1 "2012-03-10T14:13:27Z")

</div>

Hi!

Since yesterday morning I´m googleing searching for an answer and I´m not able to find it, here is my problem:

I have an Arrays that contains the names of MovieClips:

```auto
var MyMCs:Array = ["A","B","C","D","E"];

```

The actual MovieClips names are “MC\_A”, “MC\_B”, etc…, I use this method so I reuse the same Array for multiple tasks, I simply add what ever it’s needed to the name to match the task at hand. On this case I add “MC\_”.

Then I have multiple Arrays, with the same names of the values of MyMCs.  
The values of each these Arrays are the names of buttons that are inside the movieclips of MyMCs:

```auto
var A:Array = ["RR","TT"];
var B:Array = ["YY","UU"];
etc...

```

I could add a listener to a button this way:

```auto
MC_A.YY.addEventListener(MouseEvent.CLICK, DoSomething)

```

My problem is that i want it to be done dynamically, using the Arrays values in a loop to add Listeners to the all buttons. The loop system is not a problem for me… my real problem is in the dynamic attribution itself.  
Here is what I have:

```auto
//'i' and 'j' have previously been created
for(i=0; i<MyMCs.length; i++){
    for(j=0; j<this[MyMCs*].length; j++){
            root["MC_"+MyMCs*].this[MyMCs*][j].addEventListener(MouseEvent.CLICK, DoSomething);
    }
}

```

Explaning the code:  
_root[“MC\_”+MyMCs]_\* values are “MC\_A”, “MC\_B”, etc…  
_this[MyMCs][j]_\* values are “RR”, “TT”, “YY”, “UU”, etc…

I know that this is correct since I tried them separately and I can trace the proper values.

I know that my problem is in the “this” since I get an error message stating:  
1084: Syntax error: expecting identifier before this.

I suppose it should state something else… I tryed with “root”, “parent”, “child”, “MovieClip”… with no luck…

Can anyone give me a hand?
