【问题标题】:AS3 - Countdown timer color changeAS3 - 倒数计时器颜色变化
【发布时间】:2014-07-01 17:39:40
【问题描述】:

借助在线教程,我创建了一个简单的 60 秒倒数计时器。一旦计时器达到 10 秒,我真的希望文本颜色变为红色。任何线索我可以如何添加到这个 AS 来实现这一点?

额外问题:当计时器达到零时,我希望整个文本字段淡出,这样零就不再可见了。对此有什么想法吗?

这是我的代码,谢谢!!!

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();
}

【问题讨论】:

    标签: actionscript-3 timer countdown


    【解决方案1】:

    要更改颜色,请将 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);
    }
    

    【讨论】:

    猜你喜欢
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    相关资源
    最近更新 更多