as3 计时器不会停止也不会重置
as3 timer not stopping nor will reset
我正在使用 actionscript 3 构建一个时钟,我希望能够启动、停止和重置计时器。我已经开始工作了。我让其他人在工作,但突然什么都没有了?我不确定是不是因为我添加了更多代码并在时间线中放入了额外的关键帧,但肯定不会,因为启动计时器可以正常工作。
下面是我的代码:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var time = new Date();
var seconds = time.seconds;
var minutes = time.minutes;
var hours = time.hours;
var myTimer: Timer = new Timer(1000);
var secondTimer: Timer = new Timer(12000); //12 seconds
myStartButton.addEventListener(MouseEvent.CLICK, startTimer);
myStopButton.addEventListener(MouseEvent.CLICK, stopTimer);
myResetButton.addEventListener(MouseEvent.CLICK, resetTimer);
myTimer.addEventListener(TimerEvent.TIMER, secondAndMinuteRotate);
secondTimer.addEventListener(TimerEvent.TIMER, hourRotate);
function startTimer(event: MouseEvent): void
{
myTimer.start();
secondTimer.start();
}
function stopTimer(event: MouseEvent): void
{
myTimer.stop(); //here's my issue
secondTimer.stop();
}
function resetTimer(event: MouseEvent): void
{
myTimer.reset(); //and here's my other issue
secondTimer.reset();
}
function secondAndMinuteRotate(event: TimerEvent): void
{
mySecondHand.rotation += 6;
myMinuteHand.rotation += 0.1;
}
function hourRotate(event: TimerEvent): void
{
myHourHand.rotation += 0.1;
}
if (hours < 12)
{
amOrPm.text = "AM";
}
else if (hours > 12)
{
hours = hours - 12;
}
if(hours < 10)
{
hours = "0" + hours;
}
if(minutes < 10)
{
minutes = "0" + minutes;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
digitalText.text = hours + ':' + minutes + ':'+ seconds;
在第一帧代码中添加stop();
我正在使用 actionscript 3 构建一个时钟,我希望能够启动、停止和重置计时器。我已经开始工作了。我让其他人在工作,但突然什么都没有了?我不确定是不是因为我添加了更多代码并在时间线中放入了额外的关键帧,但肯定不会,因为启动计时器可以正常工作。
下面是我的代码:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var time = new Date();
var seconds = time.seconds;
var minutes = time.minutes;
var hours = time.hours;
var myTimer: Timer = new Timer(1000);
var secondTimer: Timer = new Timer(12000); //12 seconds
myStartButton.addEventListener(MouseEvent.CLICK, startTimer);
myStopButton.addEventListener(MouseEvent.CLICK, stopTimer);
myResetButton.addEventListener(MouseEvent.CLICK, resetTimer);
myTimer.addEventListener(TimerEvent.TIMER, secondAndMinuteRotate);
secondTimer.addEventListener(TimerEvent.TIMER, hourRotate);
function startTimer(event: MouseEvent): void
{
myTimer.start();
secondTimer.start();
}
function stopTimer(event: MouseEvent): void
{
myTimer.stop(); //here's my issue
secondTimer.stop();
}
function resetTimer(event: MouseEvent): void
{
myTimer.reset(); //and here's my other issue
secondTimer.reset();
}
function secondAndMinuteRotate(event: TimerEvent): void
{
mySecondHand.rotation += 6;
myMinuteHand.rotation += 0.1;
}
function hourRotate(event: TimerEvent): void
{
myHourHand.rotation += 0.1;
}
if (hours < 12)
{
amOrPm.text = "AM";
}
else if (hours > 12)
{
hours = hours - 12;
}
if(hours < 10)
{
hours = "0" + hours;
}
if(minutes < 10)
{
minutes = "0" + minutes;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
digitalText.text = hours + ':' + minutes + ':'+ seconds;
在第一帧代码中添加stop();