# Targeting Buttons In A For Loop

**URL:** <https://forum.kirupa.com/t/targeting-buttons-in-a-for-loop/234764>\
**Category:** flash\
**Created:** [August 5, 2007, 11:57pm UTC](https://forum.kirupa.com/t/targeting-buttons-in-a-for-loop/234764 "2007-08-05T23:57:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomyknoker](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@tomyknoker](https://forum.kirupa.com/u/tomyknoker)\
**Post date:** [August 5, 2007, 11:57pm UTC](https://forum.kirupa.com/t/targeting-buttons-in-a-for-loop/234764/1 "2007-08-05T23:57:58Z")

</div>

Hi all… I had the following script which worked fine for my buttons which were sitting on the stage and are called ‘btn1’, ‘btn2’, etc… However I wanted to animate all the buttons so have put them all into a movie clip called buttons, but now my script doesn’t work, I have tried changing all the this targets to \_root.buttons.this, but no luck… Any ideas anybody?

```auto
numOfBtn = 5;
stop();
for (i=0; i<numOfBtn+1; i++) {
    this["btn"+i].num = i;
	this["btn"+i].originalY = this["btn"+i]._y; //stores original position
    this["btn"+i].onRelease = function() {
        //set the frameNum variable to the same as the number button you selected, i use it again in frame 9 
		frameNum = this.num;
		trace("playhead should be sent to "+frameNum+" by btn"+this.num);
		//start playing the movie
		play();
    };
    this["btn"+i].onRollOver = function() {
        this.play();
        for (var j:Number = this.num+1; j<=numOfBtn; j++) {
		var newNum:Number = this._parent["btn"+j].originalY + 25;
		this._parent["btn"+j].tween("_y", newNum, .5, "easeOutQuad");
		_root.line.tween("_y", _root.line.originalY + 25, .5, "easeOutQuad");
		}
    };
    this["btn"+i].onRollOut = function() {
		for (var j:Number = this.num+1; j<=numOfBtn; j++) {
	var newNum:Number = this._parent["btn"+j].originalY;
	this._parent["btn"+j].tween("_y", newNum, .5, "easeOutQuad");
	_root.line.tween("_y", _root.line.originalY, .5, "easeOutQuad");
	}
        this.onEnterFrame = function() {
            if (this._currentframe != 1) {
                this.prevFrame();
            } else {
                delete this.onEnterFrame;
            }
        };
    };
}

```
