# AS2 Help with functions applied to button array

**URL:** <https://forum.kirupa.com/t/as2-help-with-functions-applied-to-button-array/274937>\
**Category:** flash\
**Created:** [November 6, 2008, 6:07pm UTC](https://forum.kirupa.com/t/as2-help-with-functions-applied-to-button-array/274937 "2008-11-06T18:07:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stanmc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@stanmc](https://forum.kirupa.com/u/stanmc)\
**Post date:** [November 6, 2008, 6:07pm UTC](https://forum.kirupa.com/t/as2-help-with-functions-applied-to-button-array/274937/1 "2008-11-06T18:07:46Z")

</div>

Hi - I have some functions that when applied directly to buttons work as planned, but when I create a function from them to apply to the array, they fail to execute properly.

Trace tells me the arrays are being parsed correctly, so the problem is in the functions themselves.

This function is meant to set all 56 buttons to alpha 0, and as unselected.  
What happens is the buttons flash onscreen at 100% before setting to alpha 0. They do behave as if unselected, but don’t know if that’s due to the code.

```auto
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onEnterFrame = function() {
		this._alpha = 0;
		this.bSelected = false;
		this.onEnterFrame = null;
	}
}

```

This function should fade the button up on rollover. But on rollover the button only increase by 10% then stops. Each subsequent rollover increases it another 10%.

```auto
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRollOver = function() {
		this._alpha<100 ? this._alpha += 10 : this.onEnterFrame = "";
	}
}

```

This function should fade the button out on rollout. Since the rollover increases them only by 10% increments (above), the result is the buttons just bounce back and forth between alpha 20 and 30.

```auto
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRollOut = function() {
		  (this._alpha>20 && this.bSelected==false) ? this._alpha -= 10 : this.onEnterFrame = "";
	}
}

```

Last one =)  
this function should set several behaviors on release. Right now none of them appear to work.

```auto
for (_root.i = 0;i<56;i++){
_root["btn"+_root.i].onRelease = function() {
		this.bSelected = true;
		this.enabled = false;
		pastBtn.enabled = true;
		pastBtn._alpha = 20;
		pastBtn.bSelected = false;
		pastBtn = this;
	}
}

```

Thanks for your help. :puzzled:
