使用按钮[as3]启动和停止间隔

时间:2016-08-29 17:48:10

标签: actionscript-3 flash actionscript

我尝试制作两个按钮,一个启动间隔,一个停止。 这是我的代码:

s_start.addEventListener(MouseEvent.CLICK, startRepeater);
s_stop.addEventListener(MouseEvent.CLICK, stopRepeater);

function startRepeater(e:MouseEvent) : void {
setInterval(repeater,500);
}

function stopRepeater(e:MouseEvent) : void {
clearInterval(repeater);
}

启动按钮完美运行!但停止按钮不是。 1067:将Function类型的值隐式强制转换为不相关的类型uint。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

clearInterval函数接受无符号整数,该整数是您创建的不是函数的区间的id。有关详细信息,请查看此 tutorial

所以你可能想尝试这样的事情

var intervalId:uint;

s_start.addEventListener(MouseEvent.CLICK, startspam);
function startspam(e:MouseEvent):void {
    intervalId = setInterval(spam,500);
}

s_stop.addEventListener(MouseEvent.CLICK, stopspam);
function stopspam(e:MouseEvent):void {
    clearInterval(intervalId);
}
相关问题