# Enabling Buttons True or False Problem

**URL:** <https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295>\
**Category:** Uncategorized\
**Created:** [February 21, 2004, 10:47pm UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295 "2004-02-21T22:47:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MArll](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@MArll](https://forum.kirupa.com/u/MArll)\
**Post date:** [February 21, 2004, 10:47pm UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295/1 "2004-02-21T22:47:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 11:05pm UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295/2 "2004-02-21T23:05:35Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 11:48pm UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295/3 "2004-02-21T23:48:42Z")

</div>

```auto
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);
	};
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2004, 1:50am UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295/4 "2004-02-22T01:50:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2004, 1:56am UTC](https://forum.kirupa.com/t/enabling-buttons-true-or-false-problem/102295/5 "2004-02-22T01:56:18Z")

</div>

Welcome MArll 🙂
