Multiple buttons HELP!

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 :slight_smile: 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]

[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.;(

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(-:

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

J