as3 Timer倒计时程序
作者:admin 日期:2009-12-17
as3 Timer倒计时程序和捕获键盘事件
var tempcount:int=0;//临时计数变量
var totaltime:int=10;//游戏默认玩10秒钟。
var gameTimer:Timer=new Timer(1000);//1秒钟刷新一次
gameTimer.addEventListener(TimerEvent.TIMER,gameTimerHandler);
function gameTimerHandler(event:TimerEvent){
tempcount++;
if(tempcount>totaltime-1){
hint_txt.text="游戏时间已经结束!";
tempcount=0;
gameTimer.stop();
}else{
hint_txt.text="游戏时间剩余: "+(totaltime-tempcount)+" 秒";
}
}
start_btn.addEventListener(MouseEvent.MOUSE_DOWN,start_btn_func);
function start_btn_func(evt:MouseEvent){
gameTimer.start();//开始计时
hint_txt.text="游戏时间剩余: "+totaltime+" 秒";
}
var tempcount:int=0;//临时计数变量
var totaltime:int=10;//游戏默认玩10秒钟。
var gameTimer:Timer=new Timer(1000);//1秒钟刷新一次
gameTimer.addEventListener(TimerEvent.TIMER,gameTimerHandler);
function gameTimerHandler(event:TimerEvent){
tempcount++;
if(tempcount>totaltime-1){
hint_txt.text="游戏时间已经结束!";
tempcount=0;
gameTimer.stop();
}else{
hint_txt.text="游戏时间剩余: "+(totaltime-tempcount)+" 秒";
}
}
start_btn.addEventListener(MouseEvent.MOUSE_DOWN,start_btn_func);
function start_btn_func(evt:MouseEvent){
gameTimer.start();//开始计时
hint_txt.text="游戏时间剩余: "+totaltime+" 秒";
}
评论: 0 | 引用: 0 | 查看次数: 553
发表评论
上一篇
下一篇


文章来自:
Tags:
相关日志:






