# Adding button actions in loop

**URL:** <https://forum.kirupa.com/t/adding-button-actions-in-loop/286650>\
**Category:** flash\
**Created:** [April 18, 2009, 11:57am UTC](https://forum.kirupa.com/t/adding-button-actions-in-loop/286650 "2009-04-18T11:57:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arkade](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Arkade](https://forum.kirupa.com/u/Arkade)\
**Post date:** [April 18, 2009, 11:57am UTC](https://forum.kirupa.com/t/adding-button-actions-in-loop/286650/1 "2009-04-18T11:57:28Z")

</div>

Hey,

I’m trying to add button actions in a loop.

In the scene i have one empty movie clip.  
The loop code in this MC clip looks like this

```auto
for (i=0; i<_root.myImagesTotal; i++) {
imageURL = _root.myImages*.attributes.url;
container_mc.duplicateMovieClip("container_mc"+i, this.getNextHighestDepth(), {_x:30, _y:50+i*220});
this["container_mc"+i]._xscale = 30;
this["container_mc"+i]._yscale = 30;
this["container_mc"+i].loadMovie(imageURL);

this["container_mc"+i].onRelease = function () {
trace(i);
} 
}

```

It’s loads all the images OK but I can’t click them.  
I swapped the .onRelease for this;

```auto
this.onPress = function () {
trace(i);
} 

```

This makes the MC’s clickable but it always traces ‘6’ no matter which one I click.

I want to get ‘1’ when I click the first MC, ‘2’ when I click the second and so on.  
Any suggestions?
