我是一名教师,一直在寻找一个可自定义的倒数计时器在课堂上使用(我也希望能够嵌入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.n" + 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.n" + 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();
}