0

这可能吗?我有一个文件,当用户在另一个元素上扮演角色时,会在其中启动影片剪辑。为了让用户体验更愉快,这会在使用 setInterval 延迟 3 秒后发生。如果用户在 3 秒结束之前滚下元素,有没有办法停止和重置这个时间?

var xTimer = setInterval(wait, 3000);
function wait(){
    show('all');
    play('all');
    clearInterval(xTimer);
}

上面是我用来设置延迟的代码,下面是我假设会中断和重置计时器的代码。

invisBtn.onRollOut = function(){
  rollover_mc.gotoAndStop(1);
  stop();
  clearInterval(xTimer());
  trace('off');
}

对此的任何帮助将不胜感激。

4

1 回答 1

0

First, the setInterval & clearInterval functions use a Number variable to work.

setInterval() returns a Number variable, and clearInterval() takes that Number in parameter to remove the previous started interval. Here you seem to keep the interval ID inside a function variable instead of a Number one.

Thus, clearInterval(xTimer()); should in reality be clearInterval(xTimer); (without the parenthesis after xTimer).

And secondly, so you can use it in the invisBtn.onRollOut function, just be sure that the xTimer variable is scoped correctly (not inside a function where the invisBtn.onRollOut isn't also), and not on different keyframes of the timeline (timeline keyframes in Flash tends to forget the code you've written on it as soon as the reading head passes onto a new keyframe of the layer which has the code on it).

Feel free to ask more details if you need !

于 2012-05-28T15:55:21.993 回答