加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash倒计时

发布时间:2020-12-15 07:19:50 所属栏目:百科 来源:网络整理
导读:工作要求做一个flash倒计时。功能:play,pause,提醒时间变色,时间到停止,可以延时计时。 context是动态文本的实例名称,playpause_mc是影片剪辑按钮的实例名称。 import flash.utils.Timer;import flash.events.TimerEvent;//默认defminute分钟,提醒时间re

工作要求做一个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 true
playpause_mc.gotoAndStop("play");
playpause_mc.buttonMode = true;

currSec = defTime;
showTime(currSec);

//creat a new Timer
var minuteTimer:Timer = new Timer(1000,currSec);

//designates listeners for the interval and completion events
minuteTimer.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 position
		isPaused = false;
		//reverse the appearance of the button
		playpause_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 buttons
		playpause_mc.gotoAndStop("play");
		minuteTimer.stop();
	}
}

function onTick(event:TimerEvent):void
{
	if (isTimeUp)
	{
		//延时后第一次开始计时,currSec初始值设置0,延时未超时 isOverTime false
		if (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 buttons
	playpause_mc.gotoAndStop("play");
	dformat.size = 40;
	countext.text = "Time Up!";
	countext.setTextFormat(tformat);
	countext.x = 4;
	countext.y = 10;
	isTimeUp = true;//超时flag
	isOverTime = 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);
	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读