如何在定时器运行降低定时器的时间(ActionScript 3.0中) [英] How to reduce the timer's time while timer is running (ActionScript 3.0)

查看:196
本文介绍了如何在定时器运行降低定时器的时间(ActionScript 3.0中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况,我做不减少它的时间,每当一个函数被调用的计时器。什么code我会改变或增加,以减少时间在我的定时器?

In my case, the timer I make doesn't reduce its time whenever a function is called. What code will I change or add in order to reduce the time in my timer?

定时code:

var count:Number = 1200;
var lessTime:Number = 180;
var totalSecondsLeft:Number = 0;
var timer:Timer = new Timer(1000, count);
timer.addEventListener(TimerEvent.TIMER, countdown);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timesup);

function countdown(event:TimerEvent) {
    totalSecondsLeft = count - timer.currentCount;
    this.mainmc.time_txt.text = timeFormat(totalSecondsLeft);
}

function timeFormat(seconds:int):String {
var minutes:int;
var sMinutes:String;
var sSeconds:String;
if(seconds > 59) {
    minutes = Math.floor(seconds / 60);
    sMinutes = String(minutes);
    sSeconds = String(seconds % 60);
    } else {
    sMinutes = "";
    sSeconds = String(seconds);
}
if(sSeconds.length == 1) {
    sSeconds = "0" + sSeconds;
}
return sMinutes + ":" + sSeconds;
}

function timesup(e:TimerEvent):void {
    gotoAndPlay(14);
}

此时 timer.start(); 放置在框架,使得定时器开始当它进入帧

At this point the timer.start(); is placed on a frame so that the timer starts as it enters the frame.

推荐答案

定时器延迟属性是什么您正在寻找。在处理程序,改变定时器的延迟:

The delay property on Timer is what you are looking for. In your handler, change the timer's delay:

function countdown(event:TimerEvent)
{
    totalSecondsLeft = count - timer.currentCount;
    this.mainmc.time_txt.text = timeFormat(totalSecondsLeft);

    //change the timer delay
    timer.delay -= lessTime;
}

我承担的,你想减去 lessTime 从每个定时器间隔计时器延迟你的code样本。如果要更改延迟到别的东西,那么就相应地调整code。

I assumed by your code sample that you wanted to subtract lessTime from the timer delay on each timer interval. If you want to change the delay to something else, then just adjust the code accordingly.

更新
上述code是用于降低每个定时器火之间的时间间隔(延迟)。如果你想要做的是减少区间(的repeatCount )需要定时器达到量 TIMER_COMPLETE ,那么你想改变定时器的repeatCount 属性:

UPDATE
The above code is for decreasing the interval (delay) between each timer fire. If what you'd like to do instead is decrease the the amount of intervals (repeatCount) it takes for the timer to reach TIMER_COMPLETE, then you want to change the repeatCount property on Timer:

//set the timer fire interval to 1 second (1000 milliseconds)
//and the total timer time to 1200 seconds (1200 repeatCount)
var timer:Timer = new Timer(1000, 1200);

//reduce the overall timer length by 3 minutes
timer.repeatCount -= 300;

另一个更新
请记住,当你修改的repeatCount ,它不会影响到 CURRENTCOUNT 。由于您使用的是单独的计数变量和 timer.currentCount 来计算剩余显示的时间,它不看像什么正在发生变化。它实际上是虽然 - 定时器将完成前,显示的时间将递减至零。为了让您的时间留给显示准确,请务必从减去相同数量计数因为你是从的repeatCount

ANOTHER UPDATE
Keep in mind that when you alter the repeatCount, it doesn't affect the currentCount. Since you are using a separate count variable and timer.currentCount to calculate the displayed time remaining, it doesn't look like anything is changing. It actually is though - the timer will complete before the displayed time counts down to zero. To keep your time left display accurate, make sure to subtract the same amount from count as you are from repeatCount:

timer.repeatCount -= 300;
count -= 300;

这篇关于如何在定时器运行降低定时器的时间(ActionScript 3.0中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆