AS3 - 倒数计时器的颜色变化计时器、倒数、颜色

由网友(倾城一夜雪)分享简介:通过一个在线教程的帮助下,我创建了一个简单的60秒倒数计时器。我真的很喜欢的文字颜色变为红色一旦定时打10秒。任何线索我怎么可以添加到这个AS要做到这一点?奖金的问题:当计时器降为零,我会为整个文本字段爱淡出,使得零点不再可见。对此有何想法?下面是我的code,谢谢你!VAR NCOUNT:数= 60;VAR myT...

通过一个在线教程的帮助下,我创建了一个简单的60秒倒数计时器。我真的很喜欢的文字颜色变为红色一旦定时打10秒。任何线索我怎么可以添加到这个AS要做到这一点?

奖金的问题:当计时器降为零,我会为整个文本字段爱淡出,使得零点不再可见。对此有何想法?

下面是我的code,谢谢你!

  VAR NCOUNT:数= 60;
VAR myTimer:定时器=新的Timer(1000,NCOUNT);

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

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

功能倒计时(E:TimerEvent):无效
{
    nCount--;
    timer_txt.text = nCount.toString();
}
 
计时器哪里有厂家直供

解决方案

要更改颜色,添加一个if语句到你的 TimerEvent.TIMER 处理程序。

要淡出末,添加一个监听 TimerEvent.COMPLETE

 进口flash.events.TimerEvent;
进口fl.transitions.Tween;
进口fl.transitions.easing.None;

VAR NCOUNT:数= 60;
VAR myTimer:定时器=新的Timer(1000,NCOUNT);

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

myTimer.addEventListener(TimerEvent.TIMER,倒计时);
//添加一个完整的监听器淡出文本字段
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE,淡出);

功能倒计时(E:TimerEvent):无效
{
    nCount--;
    如果(NCOUNT == 10)
    {
        //如果计数为10,切换文本颜色为红色
        timer_txt.textColor =为0xFF0000;
    }
    timer_txt.text = nCount.toString();
}

功能淡出(E:TimerEvent):无效
{
    //我preFER GreenSock的补间,但这是你如何用BUIL闪光灯吐温做
    VAR T:吐温=新吐温(timer_txt,阿尔法,None.easeNone,1,0,5,真正的);
}
 

With the help of an online tutorial, I created a simple 60 second countdown timer. I'd really like the text color to change to red once the timer hits 10 seconds. Any clue how I can add to this AS to make that happen?

Bonus question: when the timer hits zero, I'd love for the entire text field to fade out so that the zero isn't visible anymore. Any thoughts on that?

Here's my code, and thank you!!!

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

解决方案

To change the color, add an if statement to your TimerEvent.TIMER handler.

To fade out at the end, add a listener for 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);
}

阅读全文

相关推荐

最新文章