# \[Flash8/AS2\] Help Needed Regarding For Loops and Buttons

**URL:** https://forum.kirupa.com/t/flash8-as2-help-needed-regarding-for-loops-and-buttons/293633
**Category:** flash
**Created:** [July 31, 2009, 4:44pm UTC](https://forum.kirupa.com/t/flash8-as2-help-needed-regarding-for-loops-and-buttons/293633 "2009-07-31T16:44:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jimbobian](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jimbobian](https://forum.kirupa.com/u/jimbobian)
#### Post date: [July 31, 2009, 4:44pm UTC](https://forum.kirupa.com/t/flash8-as2-help-needed-regarding-for-loops-and-buttons/293633/1 "2009-07-31T16:44:15Z")

</div>

I have this code:

```auto
for (z=0; z<maxItems; z++) {
    _root["item_"+z].onRelease = function() {
        for (g=0; g<maxItems; g++) {
            if (g != z) {
                _root["item_"+g]._visible = false;
                _root["itemArtist_"+g]._visible = false;
                _root["itemName_"+g]._visible = false;
                _root["itemContainer_"+g]._visible = false;
                looking = false;
            }
        }
    };
}

```

However, when the user clicks on the item, the:

```auto
if (g != z) {

```

line is now redundant because the z has already looped right through to the end, so the program has no idea which button has been clicked.  
Is there a different way of doing this, bearing in mind there is hundreds of buttons so I would rather not make could for every single one!
