当前位置: 代码迷 >> Web前端 >> as3 记时代码
  详细解决方案

as3 记时代码

热度:245   发布时间:2012-08-26 16:48:06.0
as3 倒计时代码
Show_txt.text = TimeLeft(2012, 6, 1, 24); 
function TimeLeft(year, month, day, hour) { 
var mydate = new Date(); 
y = mydate.getFullYear(); 
m = mydate.getMonth()+1; 
d = mydate.getDate(); 
h = mydate.getHours(); 
if (year<y) { 
return "你错过了奥运会开幕式哦!"; 
} 
if (month<m and year == y) { 
return "你错过了奥运会开幕式哦!"; 
} 
if (day<=d and year == y and m == month) { 
if (hout>h) { 
return "今天就是奥运会!还有"+hout>h+"个小时"; 
} else { 
return "奥运会开幕式已经开始了!快去坐飞机去北京看啊~~~没飞机就坐UFO~~嘻嘻"; 
} 
} 
var DayCount = 0; 
var OK = false; 
while (!OK) { 
if (y == year and month == m) { 
OK = true; 
break; 
} 
DayCount += GetMontnDayCount(m, y); 
m++; 
if (m%13 == 0) { 
y++; 
m = 1; 
} 
} 
DayCount += day; 
DayCount -= d; 
if (hour>h) { 
h = hour-h; 
} else { 
DayCount--; 
h = 24-(hour-h); 
} 
return "距离奥运会还有"+DayCount+"天"+h+"个小时!"; 
} 
function GetMontnDayCount(m, y) { 
switch (m) { 
case 2 : 
if (y%4 == 0) { 
return 29; 
} else { 
return 28; 
} 
case 1 : 
case 3 : 
case 5 : 
case 7 : 
case 8 : 
case 10 : 
case 11 : 
return 31; 
break; 
default : 
return 30; 
break; 
} 
} 
---------------------------------------------------
var newYear = 2012;
var newMonth = 1;
var newDate = 10;
var newHours = 0;
var newMinutes = 0;
var newSeconds = 0;
function timeToCom(y, m, d, h, mm, s) {
 nowDate.setFullYear(y, m, d);
 nowDate.setHours(h);
 nowDate.setMinutes(mm);
 nowDate.setSeconds(s);
 now_com = int(nowDate.getTime()/1000);
 olympic_com = int(olympicDate.getTime()/1000)-now_com;
 countTime();
 olyTime = setInterval(countTime, 1000);
 today_text.text = "今天是"+nowDate.getFullYear()+"年"+(nowDate.getMonth()+1)+"月"+nowDate.getDate()+"日"+" "+getWeek(nowDate.getDay());
}
function countTime() {
 olympic_com--;
 olympic_days = int(olympic_com/86400);
 olympic_hours = int((olympic_com-olympic_days*3600*24)/3600);
 olympic_minutes = int((olympic_com-olympic_days*3600*24-olympic_hours*3600)/60);
 olympic_secondes = int(olympic_com-olympic_days*3600*24-olympic_hours*3600-olympic_minutes*60);
 if (olympic_days<0) {
  jieguo.text = olympic_days+" 天 "+(olympic_hours>-10 ? ("-0"+(-olympic_hours)) : olympic_hours)+" 时 "+(olympic_minutes>-10 ? ("-0"+(-olympic_minutes)) : olympic_minutes)+" 分 "+(olympic_secondes>-10 ? ("-0"+(-olympic_secondes)) : olympic_secondes)+" 秒";
 } else {
  jieguo.text = olympic_days+" 天 "+(olympic_hours<10 ? ("0"+olympic_hours) : olympic_hours)+" 时 "+(olympic_minutes<10 ? ("0"+olympic_minutes) : olympic_minutes)+" 分 "+(olympic_secondes<10 ? ("0"+olympic_secondes) : olympic_secondes)+" 秒";
 }
}
function getWeek(id) {
 switch (id) {
 case 1 :
  return ("星期一");
  break;
 case 2 :
  return ("星期二");
  break;
 case 3 :
  return ("星期三");
  break;
 case 4 :
  return ("星期四");
  break;
 case 5 :
  return ("星期五");
  break;
 case 6 :
  return ("星期六");
  break;
 case 0 :
  return ("星期日");
  break;
 default :
  break;
 }
 // End of switch
}
var nowDate = new Date();
var y = nowDate.getFullYear();
var m = nowDate.getMonth()+1;
var d = nowDate.getDate();
var h = nowDate.getHours();
var mm = nowDate.getMinutes();
var s = nowDate.getSeconds();
var timeStr = y+"-"+m+"-"+d+"-"+h+"-"+mm+"-"+s;
var nowDate = new Date();
var olympicDate = new Date();
this.onEnterFrame = function() {
 if (timeStr != undefined) {
  var _l2 = timeStr;
  var _l4 = int(_l2.split("-")[0]);
  var _l3 = int(_l2.split("-")[1])-1;
  var _l5 = int(_l2.split("-")[2]);
  var _l7 = int(_l2.split("-")[3]);
  var _l8 = int(_l2.split("-")[4]);
  var _l6 = int(_l2.split("-")[5]);
  delete this["onEnterFrame"];
  //距离时间点
  olympicDate.setFullYear(int(newYear), int(newMonth)-1, int(newDate));
  olympicDate.setHours(int(newHours));
  olympicDate.setMinutes(int(newMinutes));
  olympicDate.setSeconds(int(newSeconds));
  timeToCom(_l4, _l3, _l5, _l7, _l8, _l6);
 }
 // end if                                 
}; 
//给你一个永远不会出错的,写多长都可以还能控制打字效果的速度,舞台有一个动态文本,名字为:my_txt。在第一桢上写:
var counter:Number = 0;
var speed:Number = 200;
//这是速度控制,单位毫秒,别小于20
txtBespeak("\t时间过的真快呀,呵呵 ………………!");
//写多长都可以
function txtBespeak(txt:String)
{
 _root.my_txt.text = "";
 var arr:Array = txt.split("");
 thisTime = setInterval(rr, speed, arr);
}
function rr(arr:Array)
{
 _root.my_txt.text += arr[counter];
 counter++;
 if (counter == arr.length)
 {
  counter = 0;
  clearInterval(thisTime);
 }
} 

--------------------------------------------
54321形式的倒计时 默认要12帧的频率播放

最佳答案第一帧加入一个动态文本框,设置其名称为“aa”(属性面板实例名称处设置),再分别在第2帧和第13帧插入关键帧。然后分别设置这三个关键帧的帧动作:
第1帧:
var m:Number = 5;
aa.text=m;
第2帧:
aa.text=m;
if(m==0){
 gotoAndPlay(14);
}
第13帧:
m=m-1;
gotoAndPlay(2);

最后从第14帧开始做你的动画即可
------------------------
设定一个时间来倒计时 timer方法


var timers:Timer;
var time:Number;

time=10;
timers=new Timer(1000,time);
timers.addEventListener(TimerEvent.TIMER,timeCount);
timers.addEventListener(TimerEvent.TIMER_COMPLETE,overTime);
timers.start();

function timeCount(event:TimerEvent):void {
txt.text=(time-event.target.currentCount)+"";//currentCount是用来表示事件被触发的总次数,本例中timers是1000即1秒每次;
}
function overTime(event:TimerEvent):void {
trace("时间到!");
timers.reset();
timers.start();

}
 

?

  相关解决方案