让倒数计时器旋转而不是勾选秒针
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了让倒数计时器旋转而不是勾选秒针相关的知识,希望对你有一定的参考价值。
我是一名教师,一直在寻找可在课堂上使用的可自定义倒数计时器(我也希望能够将它嵌入Powerpoint)。
我发现下面的代码可以工作,但我想刷新图形,并可能使秒针旋转平滑而不是勾选。
图形方面不是问题,但我正在努力解决代码问题。我可以通过改变让手以较小的增量移动
hand.rotation +=6;
// to
hand.rotation +=1;
但它仍然只以每秒1次递增的速度移动。有人能指出我正确的方向吗?
代码:
// "Countdown Timer" by Lemmyz
//variables
var count:int;
var timer:Timer = new Timer(1000);
//Sound objects
var alertSnd:Sound = new Alert();
var endSnd:Sound = new AlertEnd();
var startSnd:Sound = new AlertStart();
//Button event listeners
btnStart.addEventListener(MouseEvent.MOUSE_UP, timerStart);
btnStop.addEventListener(MouseEvent.MOUSE_UP, timerStop);
btnReset.addEventListener(MouseEvent.MOUSE_UP, timerReset);
btnOK.addEventListener(MouseEvent.MOUSE_UP, setCount);
//timer object
timer.addEventListener(TimerEvent.TIMER, rot);
//init
txt.text = "Set countdown seconds";
btnStart.enabled = false;
btnReset.enabled = false;
btnStop.enabled = false;
//Functions
function setCount(evt:MouseEvent):void
{
count = parseInt(inputNum.text);
btnStart.enabled = true;
txt.text = "Press START.
" + count + " secs remaining";
}
function timerStart(evt:MouseEvent):void
{
endSnd.play();
timer.start();
btnStart.enabled = false;
btnReset.enabled = false;
btnOK.enabled = false;
btnStop.enabled = true;
}
function timerStop(evt:MouseEvent):void
{
timer.stop();
btnStop.enabled = false;
btnReset.enabled = true;
btnStart.enabled = true;
btnStart.label = "RESUME";
}
function timerReset(evt:MouseEvent):void
{
timer.stop();
hand.rotation = 0;
count = parseInt(inputNum.text);
btnStop.enabled = false;
btnReset.enabled = false;
btnOK.enabled = true;
btnStart.label = "START";
txt.text = "Timer reset to " + count + " secs. " + count + " secs remaining";
}
function rot(evt:TimerEvent):void
{
if (count==0)
{
timer.stop();
hand.rotation = 0;
count = 60;
btnReset.enabled = false;
btnStop.enabled = false;
btnStart.label = "START";
btnStart.enabled = true;
btnOK.enabled = true;
}
else
{
if (count==31||count==16)
{
alertSnd.play();
count--;
hand.rotation += 6;
}
else
{
count--;
hand.rotation += 6;
}
if (count==0)
{
txt.text = "Time's up! Timer is reset. Press START again.
" + count + " secs remaining.";
startSnd.play();
}
else
{
txt.text = count + " secs remaining";
}
}
}
先感谢您。
答案
这行代码意味着计时器将每秒触发一次(1000毫秒):
//variables
var timer:Timer = new Timer(1000);
如果将其更改为较小的数字,例如100,它将每100毫秒调用一次rot函数。但我可以看到你的代码中依赖于1000个数字,所以你的计时器可能无法正常工作。
我认为在你的情况下,最佳做法是“补间”手而不是改变计时器间隔。而不是hand.rotation += 6;
尝试此功能:
import fl.transitions.Tween;
...
// wherever you start the timer call tweenHand function
timer.start();
tweenHand();
...
// also instead of every hand.rotation += 6; call tweenHand function
tweenHand();
...
function tweenHand(): void {
var currRotation: Number = hand.rotation;
var myTween: Tween = new Tween(hand, "rotation", null, currRotation, currRotation + 6, 1, true);
myTween.start();
}
以上是关于让倒数计时器旋转而不是勾选秒针的主要内容,如果未能解决你的问题,请参考以下文章