Real way to disable buttons

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?

The easiest way is to apply this script to your button:[AS]on (release) {
this.enabled = false;
}
[/AS]

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

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.

sorry,useHandCursor I mean

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”

woOt!

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

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


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.

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.

Lost’s function should work fine :wink: 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!

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

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.

lost- it did indeed clear things up

thanks