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

I have this code:

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:

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!