本文介绍了不同的定时器与毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于林新在AS3我有这个倒计时,在一个单一的数字10秒显示,但我的客户希望他们能够像显示在10:00(4位)用毫秒。

[增订] http://magnixsolutions.com/clients/OT /9995MB-Scoreboard-NCR-728x90.swf - 眼下倒计时显示像09.32:93,然后08:34 THEN 07:34:91背部和泡沫时,倒计时,然后停下来00:00 。它应该显示4位数字。

这是我的codeS,在10秒显示[增订]

 进口API元素flash.text.TextField;

VAR FULLTIME:INT = 10000; //10秒
VAR updateRate:INT = 25; // 60 fps的更新率
VAR myTimer:定时器=新的定时器(1000 / updateRate,全职/ 1000 * updateRate);
VAR time_txt:文本字段=新的TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER,倒计时);

功能倒计时(E:TimerEvent):无效{
    VAR DT = myTimer.delay * myTimer.repeatCount  -  myTimer.currentCount * myTimer.delay;
    VAR秒= DT / 1000;
    VAR毫秒=(DT%1000)* 0.1; //砍至百分之一
    timer_txt.text =((秒-1,10)为0+秒:秒?)+:+(?(毫秒小于10)0+ MS:毫秒); //格式
}
 

解决方案

大多数评论在code。随意改变FPS的更新速度,如果你有25 fps的Flash应用程序中有一个在60 fps的更新速度没有意义的。

  VAR全职:INT = 10000; //10秒
VAR updateRate:INT = 60; // 60 fps的更新率
VAR myTimer:定时器=新的定时器(1000 / updateRate,全职/ 1000 * updateRate);
VAR DT:数字,秒:INT,MS:INT;

VAR timer_txt:文本字段=新的TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER,倒计时);

功能倒计时(E:TimerEvent):无效{
    DT = myTimer.delay * myTimer.repeatCount  -  myTimer.currentCount * myTimer.delay;
    秒= DT / 1000;
    MS =(DT%1000)* 0.1; //砍至百分之一
    timer_txt.text =((秒-1,10)为0+秒:秒?)+:+(?(毫秒小于10)0+ MS:毫秒); //格式
}
 

Since Im new in AS3 I have this countdown timer that displays in a single digit "10" seconds, but my client wants to them to display like in 10:00 (4 digits) with milliseconds.

[UPDATED] http://magnixsolutions.com/clients/OT/9995MB-Scoreboard-NCR-728x90.swf - Right now the countdown is showing like 09.32:93 then 08:34 THEN 07:34:91 back and froth when it counting down and then it stopped to 00:00. It should display 4 digits.

Heres my codes that displays in "10" seconds [UPDATED]

import flash.text.TextField;

var fullTime:int = 10000; // 10 seconds
var updateRate:int = 25; // 60 fps update rate
var myTimer:Timer = new Timer(1000 / updateRate, fullTime / 1000 * updateRate);
var time_txt:TextField = new TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void {
    var dt = myTimer.delay * myTimer.repeatCount - myTimer.currentCount * myTimer.delay;
    var seconds = dt / 1000;
    var ms = (dt % 1000) * 0.1; //chop to hundredths
    timer_txt.text = ((seconds < 10) ? "0" + seconds : seconds) + ":" + ((ms < 10) ? "0" +  ms : ms); //format
}
解决方案

Most comments in the code. Feel free to change fps update rate, There is no sense in 60 fps update rate if you have 25 fps flash application.

var fullTime:int = 10000; //10 seconds
var updateRate:int = 60; //60 fps update rate
var myTimer:Timer = new Timer(1000 / updateRate, fullTime / 1000 * updateRate);
var dt:Number, seconds:int, ms:int;

var timer_txt:TextField = new TextField();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void {
    dt = myTimer.delay * myTimer.repeatCount - myTimer.currentCount * myTimer.delay;
    seconds = dt / 1000;
    ms = (dt % 1000) * 0.1; //chop to hundredths
    timer_txt.text = ((seconds < 10) ? "0" + seconds : seconds) + ":" + ((ms < 10) ? "0" + ms : ms); //format
}

这篇关于不同的定时器与毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:29