Enabling Buttons True or False Problem

Hello All,

I will try an dexplain my problem as best I can.

I am used to using mc’s as buttons now and scripting them accordingly.
E.g.

btn_1.onPress=function(){
gotoAndPlay();
}

Now, I am making a lot of buttons that exist at the same time, so I want the buttons that aren’t curently active to be disabled, so I script like this, FOR EACH BUTTON:

btn_1.enabled=false;
btn_2.enabled-true;
btn_3.enabled-true;

etc…

My problem is, I am in situation where I have up to 15 buttons and I find I have to script each one which means I am having to type an enormous amount of code. I simple do not know how to economise my AS. Top that off with the fact that each button must also have a gotoAndStop function added and I am ending up with 300 + lines of code!! Just for the buttons!!

Can someone help me find a way to write a compact script for this situation??

Many thanks

marll

simple solution: use a loop

the ones i like (dont know why) are for loops for example

[AS]
//this loop will cycle throuhg btn_0, btn_1… til 14
for(var i=0; i<15; i++){
//here assign properties, for example this will unable all buttons
this[“btn_”+i].enabled=false
}
[/AS]

n = 15;//number of buttons
function controlButtons(b) {
	this["btn_"+b].enabled = false;
	for (var i = 1; i<=n; ++i) {
		if (i != b) {
			this["btn_"+i].enabled = true;
		}
	}
}
for (var j = 1; j<=n; ++j) {
	this["btn_"+j].j = j;
	this["btn_"+j].onPress = function() {
		controlButtons(this.j);
	};
}

Thankyou both for such prompt and ultimately useful replies!!

Particular thanks to Claudio. With a little modification, this script does exactly what I want. All I have to do now is try to understand how it works!!! :]

To Flash4Food. I already tried using a ‘loop’, but I could not seem to get the buttons to ‘reset’ once you had clicked on another one… Maybe I will look into it later when I have a spare 5 minutes ( an hour or two more like]

Thanks Again. I am very grateful!

marll

Welcome MArll :slight_smile: