# Target button in a loop

**URL:** <https://forum.kirupa.com/t/target-button-in-a-loop/230565>\
**Category:** Uncategorized\
**Created:** [June 27, 2007, 7:53am UTC](https://forum.kirupa.com/t/target-button-in-a-loop/230565 "2007-06-27T07:53:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trx](https://avatars.discourse-cdn.com/v4/letter/t/ecc23a/32.png) [@trx](https://forum.kirupa.com/u/trx)\
**Post date:** [June 27, 2007, 7:53am UTC](https://forum.kirupa.com/t/target-button-in-a-loop/230565/1 "2007-06-27T07:53:58Z")

</div>

I have the below code which attaches a movieclip “btn1” to another movie clip within this loop I wish to setup up different functions for each different button but it only lets me set them up for the last one in the line of buttons. How to I target each button seperatly by using a string and then the value of miniLoop? i.e

subnav.test\_mc.item1  
subnav.test\_mc.item2

code--------------------------------

for (var miniLoop=0; miniLoop \< imageLength.length; miniLoop++) {  
var currentImage = imageLength[miniLoop];  
var item\_mc = subnav.test\_mc.attachMovie(“btn1”,“item”+miniLoop, miniLoop);

```
            item_mc.onRollOver = function() {
                trace("test");
            }
            
            item_mc.onPress = function() {
                image_mc.loadMovie(this.url);
                trace(miniLoop);
                trace(desc[0]);
            }
            
            item_mc.url = currentImage.attributes.url;
            item_mc._x = miniLoop * subnav_spacing ;
        }
```
