# Delete nested onPress Event

**URL:** <https://forum.kirupa.com/t/delete-nested-onpress-event/221219>\
**Category:** Uncategorized\
**Created:** [April 2, 2007, 4:33pm UTC](https://forum.kirupa.com/t/delete-nested-onpress-event/221219 "2007-04-02T16:33:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsj4](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tsj4](https://forum.kirupa.com/u/tsj4)\
**Post date:** [April 2, 2007, 4:33pm UTC](https://forum.kirupa.com/t/delete-nested-onpress-event/221219/1 "2007-04-02T16:33:05Z")

</div>

I have 16 buttons on the stage layed out in a grid of 4\*4. When the user clicks a button it is brought to the top depth and then expands to the size of 4 buttons. The issue is I have a for loop that adds the functionality to the button. The button has a onRelease method attached to it and nested inside is a onPress action for the expanded state. I need to delete the onPress method if another button is pressed to start the button proccess over but am having a hard time. Here is my code.

```auto

function gotoURL(movieNum) {
    getURL("javascript:flashURL("+movieNum+");");
}
// ----
for (i=0; i<=16; i++) {
    this["b"+i].onRelease = function() {
        // -- bring selected button to the top deptht         
        _root.x += 2;
        this.swapDepths(_root.x);
        // -- defines last selected button and then delete it         
        var lastBtn:MovieClip;
        this._parent.lastBtn.gotoAndPlay(11);
        trace("Button Event One");
        this.gotoAndPlay(2);
        this._parent.lastBtn = this;
        updateAfterEvent();
        delete this._parent.lastBtn.onPress;
        // -- If the user clicks the on state then it goes to some URL         
        this.onPress = function() {
            //_root.gotoURL(i);             
            trace("Button Event two");
            updateAfterEvent();
        };
    };
}

```

an additional issue is the nested onPress function is not in scope of the var i which is outputing as undefined.
