flash倒计时

来源:互联网 发布:seo分析师 编辑:程序博客网 时间:2024/05/29 10:07

工作要求做一个flash倒计时。功能:play,pause,提醒时间变色,时间到停止,可以延时计时。

context是动态文本的实例名称,playpause_mc是影片剪辑按钮的实例名称。




import flash.utils.Timer;import flash.events.TimerEvent;//默认defminute分钟,提醒时间reminder分钟,currSec存储暂停时的秒数,超时另计overMinute5分钟var defminute:Number = 15;//演讲时间,请填整数,如15,即演讲时间设置15分钟var reminder:Number = 3;//提醒时间,请设置整数,如3,即剩余3分钟时开始提醒var overMinute:Number = 5;//延时时间,请设置整数,如5,即延时5分钟//设置结束 var currSec:int = 0;var defTime:int = Math.floor(defminute * 60);var reminderSec:int = Math.floor(reminder * 60);var overSec:int = Math.floor(overMinute * 60);//初始值:未开始计时,暂停状态var isPaused:Boolean = true;var isTimeUp:Boolean = false;var isOverTime:Boolean = false;//文本样式//初始文本状态var dformat:TextFormat = new TextFormat();dformat.color = 0x333333;dformat.size = 80;//提醒文本状态var sformat:TextFormat = new TextFormat();sformat.color = 0xFF6000;sformat.size = 80;//时间到文本状态var tformat:TextFormat = new TextFormat();tformat.color = 0xFF6000;tformat.size = 50;//实时变化的分钟秒var minute:int;var sec:int;//分秒的文本var minuteText:String = '';var secText:String = '';//set appearance of button, mode to trueplaypause_mc.gotoAndStop("play");playpause_mc.buttonMode = true;currSec = defTime;showTime(currSec);//creat a new Timervar minuteTimer:Timer = new Timer(1000,currSec);//designates listeners for the interval and completion eventsminuteTimer.addEventListener(TimerEvent.TIMER,onTick);minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);// movie clip button control;playpause_mc.addEventListener(MouseEvent.CLICK,clickHandler);function clickHandler(event:MouseEvent):void{if (isPaused){//change state to playing, and play sound from positionisPaused = false;//reverse the appearance of the buttonplaypause_mc.gotoAndStop("pause");//over time ,change Timer ticking;if (isTimeUp && isOverTime ){minuteTimer.repeatCount = overSec;minuteTimer.reset();minuteTimer.start();}else{//starts the timer ticking;minuteTimer.start();}}else{isPaused = true;//change the appearance of the buttonsplaypause_mc.gotoAndStop("play");minuteTimer.stop();}}function onTick(event:TimerEvent):void{if (isTimeUp){//延时后第一次开始计时,currSec初始值设置0,延时未超时 isOverTime falseif (isOverTime){currSec = 0;isOverTime = false;}if (currSec < overSec){currSec++;}else{currSec = 0;}countext.x = 0;countext.y = 0;}else{if (currSec>0){currSec--;}else{currSec = 0;}}showTime(currSec);}function onTimerComplete(event:TimerEvent):void{isPaused = true;//change the appearance of the buttonsplaypause_mc.gotoAndStop("play");dformat.size = 40;countext.text = "Time Up!";countext.setTextFormat(tformat);countext.x = 4;countext.y = 10;isTimeUp = true;//超时flagisOverTime = true;//延时超时flag}//动态文本显示时间function showTime(timesec){var time = timesec;minute = Math.floor((time / 60));sec = Math.floor((time - minute * 60));if ((minute < 10)){minuteText = '0' + String(minute);}else{minuteText = String(minute);}if ((sec < 10)){secText = '0' + String(sec);}else{secText = String(sec);}countext.text = minuteText + ':' + secText;if (timesec<reminderSec){countext.setTextFormat(sformat);}else{countext.setTextFormat(dformat);}}


0 0
原创粉丝点击