Posts Tagged ‘setInterval’

Avoid manic button press

Wednesday, July 1st, 2009

I had to create a function where by I could avoid the button being pressed to quickly as some clicks where not being registered.


Some people will click a button as quickly as they can to see if they can break it lol.

  1. var reEnable:Number;
  2. button_mc.onPress = function() {
  3.  trace("the button was pressed");
  4.  disableButton(this);
  5. };
  6. function disableButton(b:MovieClip):Void {
  7.  b.enabled = false;
  8.  clearInterval(reEnable);
  9.  reEnable = setInterval(this, "reEnableButton", 1000, b);
  10. }
  11. function reEnableButton(b:MovieClip):Void {
  12.  b.enabled = true;
  13.  clearInterval(reEnable);
  14. }