Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-倒计时计时器颜色更改_Actionscript 3_Timer_Countdown - Fatal编程技术网

Actionscript 3 AS3-倒计时计时器颜色更改

Actionscript 3 AS3-倒计时计时器颜色更改,actionscript-3,timer,countdown,Actionscript 3,Timer,Countdown,在在线教程的帮助下,我创建了一个简单的60秒倒计时。我真的很想文本颜色改变为红色,一旦计时器达到10秒。有什么线索我可以补充到这一点,使之发生吗 附加问题:当计时器达到零时,我希望整个文本字段淡出,使零不再可见。有什么想法吗 这是我的代码,谢谢 var nCount:Number = 60; var myTimer:Timer = new Timer(1000, nCount); timer_txt.text = nCount.toString(); myTimer.start(); myT

在在线教程的帮助下,我创建了一个简单的60秒倒计时。我真的很想文本颜色改变为红色,一旦计时器达到10秒。有什么线索我可以补充到这一点,使之发生吗

附加问题:当计时器达到零时,我希望整个文本字段淡出,使零不再可见。有什么想法吗

这是我的代码,谢谢

var nCount:Number = 60;
var myTimer:Timer = new Timer(1000, nCount);

timer_txt.text = nCount.toString();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void
{
    nCount--;
    timer_txt.text = nCount.toString();
}

要更改颜色,请将if语句添加到
TimerEvent.TIMER
处理程序中

要在结尾淡出,请为
TimerEvent.COMPLETE
添加一个侦听器

import flash.events.TimerEvent;
import fl.transitions.Tween;
import fl.transitions.easing.None;

var nCount:Number = 60;
var myTimer:Timer = new Timer(1000, nCount);

timer_txt.text = nCount.toString();
myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);
// add a complete listener to fade out the TextField
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, fadeOut);

function countdown(e:TimerEvent):void
{
    nCount--;
    if(nCount == 10) 
    {
        // if the count is at 10, switch the text color to red
        timer_txt.textColor = 0xFF0000;
    }
    timer_txt.text = nCount.toString();
}

function fadeOut(e:TimerEvent):void 
{
    // I prefer GreenSock for tweening, but this is how you'd do it with the buil-in Flash Tween
    var t:Tween = new Tween(timer_txt, "alpha", None.easeNone, 1, 0, .5, true);
}

这绝对是完美的。我真是太感谢你了!我有一个类似的问题,我正在为同一个项目工作,如果你愿意帮助的话: