as3计时器不停止也不会重置

时间:2015-02-18 17:14:28

标签: actionscript-3 flash timer actionscript adobe

我正在动作脚本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;

Link to File on Dropbox

1 个答案:

答案 0 :(得分:0)

在第一帧的代码中添加stop();