Home > ActionScript 2.0 > Disable all buttons in flash or disable 1 button in flash

Disable all buttons in flash or disable 1 button in flash

Recently I needed to disable all buttons on my flash site. I trawled the net looking for answers but all I got was what I already knew. Which is disabling each button 1 by 1 using an array like so:

 
//an array of button instance names
var buttonInstanceNames:Array = new Array("button1","button2",
"button3", "button4");
 
//function that sets the buttons enabled state
function enableButtons(e){
   for(var i=0;i<buttons.length;i++){>
      this[buttonInstanceNames[i]].enabled = e;
   }
}
 
//call function and assign enabled state
enableButtons(false);

This is all good if you have a few buttons but what if your site is complex like the 1 I was working on and you wanted to disable all button interactivity without knowing buttons instance names.

Solution
Basically place a movie clip button over the entire movie or just over the area where your buttons are with _alpha set to 0. Remember to set the movie clip with a onRollOver, or onRelease event. Just set the blocking movie clip's _visible state to false when you want interactivity back.

Here is the code I used to get this working.

 
//The instance name of my blocker movieclip is "mcBlocker"
//show or hide the button blocker
function enableButtons(e){
   mcBlocker._visible = e;
   mcBlocker.onRollOver = doNothing;
 }
 
//do nothing when the blocker active
function doNothing(){}
 
//just enable or disable the blocker
enableButtons(false);
 

Hope this helps..

  1. Martin
    November 23rd, 2010 at 14:36 | #1

    this is the script:

    Button.prototype.enabled = false;
    //or
    Button.prototype.enabled = true;

    in case you need to disable All buttons but only one (let’s call it “button01″) in your flash movie you can do this:

    Button.prototype.enabled = false; //all buttons are disabled including “button01″
    button01.enabled=true; //”button01″ is re-enabled for use.

    then with Button.prototype.enabled=true; //all buttons enabled again.

  2. mario
    May 13th, 2011 at 11:26 | #2

    Martin :
    this is the script:
    Button.prototype.enabled = false;
    //or
    Button.prototype.enabled = true;
    in case you need to disable All buttons but only one (let’s call it “button01″) in your flash movie you can do this:
    Button.prototype.enabled = false; //all buttons are disabled including “button01″
    button01.enabled=true; //”button01″ is re-enabled for use.
    then with Button.prototype.enabled=true; //all buttons enabled again.

    And how would be the script for Actionscript 3???

  3. jared
    December 27th, 2011 at 01:46 | #3

    does this need to be done with every single button?@mario

  1. No trackbacks yet.
SEO Powered by Platinum SEO from Techblissonline