# Multiple buttons HELP!

**URL:** <https://forum.kirupa.com/t/multiple-buttons-help/183388>\
**Category:** flash\
**Created:** [March 26, 2006, 4:04pm UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388 "2006-03-26T16:04:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smedly](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@smedly](https://forum.kirupa.com/u/smedly)\
**Post date:** [March 26, 2006, 4:04pm UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388/1 "2006-03-26T16:04:30Z")

</div>

[http://www.jasonallies.com](http://www.jasonallies.com)

If you go to my site and click on the small “PORTFOLIO 06” button you will see a “button grid” that shows different videos or photos. Unfortunately I am fairly new to actionscript and the code associated with this grid is extensive and extremely repetitive…

//Repeated for every thumbPic and thumbClip button\  
thumbPic1.onRollOver = function() {  
this.gotoAndPlay(2);  
}  
thumbPic1.onRollOut = function() {  
this.gotoAndPlay(8);  
}  
thumbPic1.onRelease = function() {  
clipHolder.\_visible = false;  
picHolder.\_visible = true;  
this.gotoAndStop(16);  
this.onRollOut = function() {  
this.gotoAndStop(16);  
}  
curPicNum = 0;  
picLoader.loadClip(“pics/pic” + curPicNum + “.jpg”, picHolder); }

…of course it is just a simple copy and paste which doesn’t take too long - but I’m assuming there has to be a better way.

JA

---

<div class="post-metadata">

**Author:** ![Liger](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@Liger](https://forum.kirupa.com/u/Liger)\
**Post date:** [March 27, 2006, 4:01am UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388/2 "2006-03-27T04:01:50Z")

</div>

> [@smedly](#):
>
> [http://www.jasonallies.com](http://www.jasonallies.com)
> 
> If you go to my site and click on the small “PORTFOLIO 06” button you will see a “button grid” that shows different videos or photos. Unfortunately I am fairly new to actionscript and the code associated with this grid is extensive and extremely repetitive…
> 
> //Repeated for every thumbPic and thumbClip button\  
> thumbPic1.onRollOver = function() {  
> this.gotoAndPlay(2);  
> }  
> thumbPic1.onRollOut = function() {  
> this.gotoAndPlay(8);  
> }  
> thumbPic1.onRelease = function() {  
> clipHolder.\_visible = false;  
> picHolder.\_visible = true;  
> this.gotoAndStop(16);  
> this.onRollOut = function() {  
> this.gotoAndStop(16);  
> }  
> curPicNum = 0;  
> picLoader.loadClip(“pics/pic” + curPicNum + “.jpg”, picHolder); }
> 
> …of course it is just a simple copy and paste which doesn’t take too long - but I’m assuming there has to be a better way.
> 
> JA

Yup, there usually is 🙂 This should work. If not send us your fla and I’ll have a look see.

[AS]  
//Whatever your movieClips are called, put em in this array.  
var aClips:Array = new Array(thumbPic1, thumbPic2, thumbPic3, thumbPic4, thumbPic5);  
//  
for (i=0; i\<aClips.length; i++) {  
var curClip:MovieClip = aClips\*;  
//  
curClip.onRollOver = function() {  
this.gotoAndPlay(2);  
};  
curClip.onRollOut = function() {  
this.gotoAndPlay(8);  
};  
curClip.onRelease = function() {  
clipHolder.\_visible = false;  
picHolder.\_visible = true;  
this.gotoAndStop(16);  
this.onRollOut = function() {  
this.gotoAndStop(16);  
};  
curPicNum = 0;  
picLoader.loadClip(“pics/pic”+curPicNum+“.jpg”, picHolder);  
};  
}  
[/AS]

---

<div class="post-metadata">

**Author:** ![smedly](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@smedly](https://forum.kirupa.com/u/smedly)\
**Post date:** [March 27, 2006, 5:13am UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388/3 "2006-03-27T05:13:11Z")

</div>

> [FONT=Courier New][LEFT][COLOR=#808080]_//Whatever your movieClips are called, put em in this array._[/COLOR]  
> [COLOR=#000000] **var** [/COLOR] aClips:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]Array[/COLOR][COLOR=#000000]([/COLOR]thumbPic1, thumbPic2, thumbPic3, thumbPic4, thumbPic5[COLOR=#000000])[/COLOR];  
> [COLOR=#808080]_//_[/COLOR]  
> [COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i=[COLOR=#000080]0[/COLOR]; i\<aClips.[COLOR=#0000ff]length[/COLOR]; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#000000] **var** [/COLOR] curClip:[COLOR=#0000ff]MovieClip[/COLOR] = aClips[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR];  
> [COLOR=#808080]_//_[/COLOR]  
> curClip.[COLOR=#0000ff]onRollOver[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]gotoAndPlay[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000]}[/COLOR];  
> curClip.[COLOR=#0000ff]onRollOut[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]gotoAndPlay[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000]}[/COLOR];  
> curClip.[COLOR=#0000ff]onRelease[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> clipHolder.[COLOR=#0000ff]\_visible[/COLOR] = [COLOR=#000000] **false** [/COLOR];  
> picHolder.[COLOR=#0000ff]\_visible[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]gotoAndStop[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]onRollOut[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]gotoAndStop[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000]}[/COLOR];  
> curPicNum = [COLOR=#000080]0[/COLOR];  
> picLoader.[COLOR=#0000ff]loadClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“pics/pic”[/COLOR]+curPicNum+[COLOR=#ff0000]“.jpg”[/COLOR], picHolder[COLOR=#000000])[/COLOR];  
> [COLOR=#000000]}[/COLOR];  
> [COLOR=#000000]}[/COLOR]  
> [/LEFT]  
> [/FONT]

Thanks - that seems to work for the button functionality… but how do I now change the curPicNum value depending on which value from the array is being called, so a different pic/clip will show depending on which button you click.;(

---

<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 27, 2006, 7:16am UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388/4 "2006-03-27T07:16:10Z")

</div>

```auto
var aClips = new Array(thumbPic1, thumbPic2, thumbPic3, thumbPic4, thumbPic5);
var oldClip;
for (i=0; i<aClips.length; i++) {
	var curClip = aClips*;
	curClip.id = i;
	curClip.onRollOver = function() {
		this.gotoAndPlay(2);
	};
	curClip.onRollOut = function() {
		this.gotoAndPlay(8);
	};
	curClip.onRelease = function() {
		clipHolder._visible = false;
		picHolder._visible = true;
		this.gotoAndStop(16);
		this.enabled = 0;
		oldClip.gotoAndPlay(8);
		oldClip.enabled = 1;
		picLoader.loadClip("pics/pic"+this.id+".jpg", picHolder);
		oldClip = this;
	};
}

```

scotty(-:

---

<div class="post-metadata">

**Author:** ![smedly](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@smedly](https://forum.kirupa.com/u/smedly)\
**Post date:** [March 27, 2006, 11:50pm UTC](https://forum.kirupa.com/t/multiple-buttons-help/183388/5 "2006-03-27T23:50:12Z")

</div>

Thanks guys. Works great:hugegrin:  
Now that I see it it seems so obvious.

J
