在在线教程的帮助下,我创建了一个简单的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();
}
答案 0 :(得分:0)
要更改颜色,请在TimerEvent.TIMER
处理程序中添加if语句。
要在最后淡出,请为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);
}