# Real way to disable buttons

**URL:** <https://forum.kirupa.com/t/real-way-to-disable-buttons/21039>\
**Category:** flash\
**Created:** [May 16, 2003, 4:38am UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039 "2003-05-16T04:38:42Z")\
**Posts on this page:** 14\
**Page:** 1

<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:** [May 16, 2003, 4:38am UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/1 "2003-05-16T04:38:42Z")

</div>

I have tryed to disable my flash buttons many times and ran into problems. I know how to disable sound buttons, but I can’t seem to get it right for my navigation. Anybody have any suggestions?

---

<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:** [May 16, 2003, 5:39am UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/2 "2003-05-16T05:39:21Z")

</div>

The easiest way is to apply this script to your button:[AS]on (release) {  
this.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:** [May 16, 2003, 4:00pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/3 "2003-05-16T16:00:43Z")

</div>

no way, thats it? r us serious? thanks mang i’ll give it a go. but just by looking at your script i’m wondering how to reinable it? by instance names, and then on all your other buttons

on(release) {  
myButton.enabled = true;  
}

quick guees but does that look right?

thanks agian

---

<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:** [May 16, 2003, 4:39pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/4 "2003-05-16T16:39:16Z")

</div>

for me, when I press the button, it call a function to enable all (which is using the enabled=true and useCursorHand=true) then  
use this.enabled= true and for the cursor as well.

---

<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:** [May 16, 2003, 4:44pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/5 "2003-05-16T16:44:49Z")

</div>

sorry,useHandCursor I mean

---

<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:** [May 16, 2003, 5:02pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/6 "2003-05-16T17:02:41Z")

</div>

Speaking of functions, here’s one I learned awhile back from lostinbeta.

You basically create a function and place it on the main timeline, something like this.[AS]function disEnable(isIt) {  
button1.enabled = isIt;  
button2.enabled = isIt;  
button3.enabled = isIt;  
button4.enabled = isIt;  
}[/AS]

To call the function, apply this to your button.[AS]on (release) {  
\_root.disEnable(false);  
}[/AS]

That will disable all 4 buttons listed in the function and to re-enable them, just apply the same script to another button, but have “false” switched to “true”

---

<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:** [May 16, 2003, 5:13pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/7 "2003-05-16T17:13:16Z")

</div>

woOt!

---

<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:** [May 16, 2003, 8:57pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/8 "2003-05-16T20:57:21Z")

</div>

Hey EG… as a slight update (did just now), if you want to disable all button symbols in a timeline you can use a for/in loop instead of each individual instance name.

[AS]function disEnable(isIt) {  
var i;  
for (i in \_root) {  
if (this\* instanceof Button) {  
this\*.enabled = isIt;  
}  
}  
}[/AS]

You call and run the function the same, but instead of only disabling certain instance names it disables all Button symbols.

If you use movie clips for symbols then change “Button” to “MovieClip” in the script.

And if the timeline containing the buttons is not the \_root timeline, change “\_root” in the script to target the correct timeline.

Heres a great tutorial on for/in loops.  
[http://www.kirupa.com/developer/actionscript/tricks/forin.asp](http://www.kirupa.com/developer/actionscript/tricks/forin.asp)

---

<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:** [May 16, 2003, 9:20pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/9 "2003-05-16T21:20:33Z")

</div>

that disEnable function has the potential of disabling other buttons as well. Looping through a clip will loop through its instances and its variables, and if a variable references a button in another scope, then that button will too be disabled which you may not want.

You could check to make sure the \_parent is the current movieclip or do something like

```auto

MovieClip.prototype.disableAllButtons = function(act) {
   if (this.enabled = !act){ if (!this.onPress) delete this.onPress;
   }else if (!this.onPress) this.onPress = null;
}

```

which actually converts the movieclip itself into a button disabling all buttons within it (not in the fact that they are disabled but the null button action of the movieclip is overriding it). This technique is faster but it will also block all buttons nested within other nested clips of that movieclip.

---

<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:** [May 16, 2003, 9:39pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/10 "2003-05-16T21:39:05Z")

</div>

ok senocular and lostinbeta you guys kinda confused me just now. are you saying make a movie clip and inside have your buttons? beacuase that is what i am getting from senocular anyway. i notice your not using buttons instances.

---

<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:** [May 16, 2003, 9:46pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/11 "2003-05-16T21:46:19Z")

</div>

Lost’s function should work fine 😉 Its only on odd occasions if you’re setting a lot of screen instance variables (like buttons) that the script may go wrong.

The “best” way in terms of ease and understanding is probably what electrongeek suggested. There you know exactly what buttons are being disabled and you can do it easily from one function call specifying whether they should be enabled or disabled. Of course it starts to get tedious the more buttons you have.

It really depends on your competence in Flash, how many buttons you have and how willing you are to type type type!

---

<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:** [May 16, 2003, 9:54pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/12 "2003-05-16T21:54:39Z")

</div>

ok thanks everyone for the insight. and yes that would get very tidious.

---

<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:** [May 16, 2003, 9:58pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/13 "2003-05-16T21:58:01Z")

</div>

Sen: Good point. I guess thats what I get for recreating the function in the most basic environment. I too would recommend the first way EG posted, I only offered my version in case you had a bunch of buttons you needed disabled, but as Sen stated, that may be problematic on occasion.

Digital: Senoculars method was using a MovieClip object prototype. His method assigns an onPress dynamic event handler to the movieClip symbol essentially making it a button in its own. If the movie clip is a button, then any button instances inside the clip will not be clickable. I hope that clears up what sen was doing.

---

<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:** [May 16, 2003, 10:06pm UTC](https://forum.kirupa.com/t/real-way-to-disable-buttons/21039/14 "2003-05-16T22:06:04Z")

</div>

lost- it did indeed clear things up

thanks
