如何在As3中单击另一个按钮时禁用X秒的功能?

时间:2017-01-02 18:45:55

标签: actionscript-3 actionscript flashdevelop

我有一个简单的问题,它变得对我来说是:

我有一个被调用的函数,并在大约11秒后运行:

var myTimeoutClickObject = setTimeout(clickObject,11000); 
function clickObject():void{
  //My code
}

我还有一个重置按钮,我为它制作了一个Click Function:

reset_btn.addEventListener(MouseEvent.CLICK, reset);
function reset(e:MouseEvent):void{
  //My code
}

现在,我想每次点击clickObject()按钮时再次禁用reset_btn功能约11秒。

我真的很感激,如果你能在这件事上帮助我的话!

提前致谢!

1 个答案:

答案 0 :(得分:2)

您可以使用标志:

var isClickDisabled:Boolean = false;

var myTimeoutClickObject = setTimeout(clickObject, 11000);

function clickObject():void{
    //My code
    if(isClickDisabled)
       return;
}

reset_btn.addEventListener(MouseEvent.CLICK, reset);

function reset(e:MouseEvent):void{
  //My code
  isClickDisabled = true;

  // call code to re-enable it later for 11sec
}

或者像这样使用clearTimeout:

clearTimeout(myTimeoutClickObject);

setTimeout(startAgain_clickObject, 11000);

function startAgain_clickObject(e:MouseEvent):void {
      myTimeoutClickObject = setTimeout(clickObject, 11000);
}