//新增一個 FLA(as3.0)
//把下面的as貼到影格上
//Ctrl + Enter 完畢


//ActionScript 3.0
var setMin:int = 6; //設定倒數時間 "分"
var setSec:int = 0; //設定倒數時間 "秒"
var total:int = setMin * 60 + setSec; //總秒數
var _txt:TextField = new TextField();
addChild(_txt);


var timer:Timer = new Timer(1000, 0);
timer.addEventListener(TimerEvent.TIMER, count);
timer.start();


function count(e:TimerEvent):void{
 var mm:String = String(Math.floor(total / 60));
 if (mm.length < 2){mm = "0" + mm; }
 var ss:String = String(total - int(mm) * 60);
 if (ss.length < 2){ss = "0" + ss; }
 _txt.text = mm + ":" + ss; //顯示倒數時間 "分:秒"


 if(total == 0){
  timer.removeEventListener(TimerEvent.TIMER, count);
  return;
 }
 total--;
}

//發佈完後,再把swf匯入到元件庫,即可。

全站熱搜
創作者介紹
創作者 BlackHawk 的頭像
BlackHawk

鐵人

BlackHawk 發表在 痞客邦 留言(0) 人氣()