Archive

Archive for February, 2009

Disable all buttons in flash or disable 1 button in flash

February 3rd, 2009 3 comments

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:

  1.  
  2. //an array of button instance names
  3. var buttonInstanceNames:Array = new Array("button1","button2",
  4. "button3", "button4");
  5.  
  6. //function that sets the buttons enabled state
  7. function enableButtons(e){
  8. for(var i=0;i<buttons.length;i++){>
  9. this[buttonInstanceNames[i]].enabled = e;
  10. }
  11. }
  12.  
  13. //call function and assign enabled state
  14. 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.

  1.  
  2. //The instance name of my blocker movieclip is "mcBlocker"
  3. //show or hide the button blocker
  4. function enableButtons(e){
  5. mcBlocker._visible = e;
  6.   mcBlocker.onRollOver = doNothing;
  7.  }
  8.  
  9. //do nothing when the blocker active
  10. function doNothing(){}
  11.  
  12. //just enable or disable the blocker
  13. enableButtons(false);
  14.  

Hope this helps..

SEO Powered by Platinum SEO from Techblissonline