# Streamline my Actionscript?

**URL:** <https://forum.kirupa.com/t/streamline-my-actionscript/183196>\
**Category:** flash\
**Created:** [March 24, 2006, 3:28pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196 "2006-03-24T15:28:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![p\_due18](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/p_due18/32/347_2.png) [@p\_due18](https://forum.kirupa.com/u/p_due18)\
**Post date:** [March 24, 2006, 3:28pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/1 "2006-03-24T15:28:56Z")

</div>

Hi there everyone,

Basically all I want to do is cut down my code so it’s a bit easier to use.

I have buttons that are called btn1, btn2, btn3, btn4, btn5…

I’m putting the script for rollovers in a frame action:

```auto
btn1.onRollOver = btn2.onRollOver = btn3.onRollOver = btn4.onRollOver = btn5.onRollOver = function() {
	this.gotoAndStop("over");
};

```

Is there a way to make it simpler? It’d be easier if I could have it something like this:

```auto
btn**[COLOR="Red"](i)[/COLOR]**.onRollOver = function(){
	this.gotoAndStop("over");
}

```

If anyone knows a way to do it I’d be very grateful.!

Cheers, Pdue

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [March 24, 2006, 3:31pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/2 "2006-03-24T15:31:52Z")

</div>

```auto
for (var i:Number = 0; i <= 5; i++) {
 this["btn" + i].onRollOver = function() {
  this.gotoAndStop("over");
 };
}

```

---

<div class="post-metadata">

**Author:** ![p\_due18](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/p_due18/32/347_2.png) [@p\_due18](https://forum.kirupa.com/u/p_due18)\
**Post date:** [March 24, 2006, 3:34pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/3 "2006-03-24T15:34:01Z")

</div>

Holy!!! That was seriously quick!!!

I’d been looking at for loops but couldn’t get them to work, this works perfectly, cheers mate!!

Pdue

---

<div class="post-metadata">

**Author:** ![p\_due18](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/p_due18/32/347_2.png) [@p\_due18](https://forum.kirupa.com/u/p_due18)\
**Post date:** [March 24, 2006, 3:42pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/4 "2006-03-24T15:42:45Z")

</div>

Sorry to bother you again,

When one of the buttons is clicked, it sends all of the buttons to an ‘off’ state and then sets the clicked button to an ‘on’ state.

Is there a way to further shorten the next part?:

```auto
this["btn" + i].onRelease = function() {
	btn1.gotoAndStop("off");
	btn2.gotoAndStop("off");
	btn3.gotoAndStop("off");
	btn4.gotoAndStop("off");
	btn5.gotoAndStop("off");
	this.gotoAndStop("selected");
	gotoAndStop(this._name);
};

```

Pdue

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 24, 2006, 3:45pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/5 "2006-03-24T15:45:10Z")

</div>

not really. Im sure you could use a function with a loop, but it will be just as long and look more confusing.

---

<div class="post-metadata">

**Author:** ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)\
**Post date:** [March 24, 2006, 3:50pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/6 "2006-03-24T15:50:47Z")

</div>

```auto
var curBtn;
for (var i = 0; i<=5; i++) {
	var btn = this["btn"+i];
	btn.onRelease = function() {
		this.gotoAndStop("selected");
		curBtn.gotoAndStop("off");
		curBtn = this;
	};
}

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 24, 2006, 3:54pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/7 "2006-03-24T15:54:40Z")

</div>

> …just as long and look more confusing.

> [@scotty](#):
>
> ```auto
> var curBtn;
> for (var i = 0; i<=5; i++) {
> var btn = this["btn"+i];
> btn.onRelease = function() {
> this.gotoAndStop("selected");
> curBtn.gotoAndStop("off");
> curBtn = this;
> };
> }
> 
> ```

Exactly…😃

---

<div class="post-metadata">

**Author:** ![p\_due18](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/p_due18/32/347_2.png) [@p\_due18](https://forum.kirupa.com/u/p_due18)\
**Post date:** [March 24, 2006, 3:55pm UTC](https://forum.kirupa.com/t/streamline-my-actionscript/183196/8 "2006-03-24T15:55:01Z")

</div>

> [@scotty](#):
>
> ```auto
> var curBtn;
> for (var i = 0; i<=5; i++) {
> var btn = this["btn"+i];
> btn.onRelease = function() {
> this.gotoAndStop("selected");
> curBtn.gotoAndStop("off");
> curBtn = this;
> };
> }
> 
> ```
> 
> scotty(-:

Man, that’s sweet, I love flash sometimes!!!

Cheers guys, you da bomb!
