Copy link to clipboard
Copied
I JUST LIKE TO SIMPLY CHANGE THIS SO CLOCK WILL RUN BACKWARDS
import flash.utils.Timer;
import flash.events.TimerEvent;
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);
function loopF(event:TimerEvent):void{
var time: Date = new Date();
//time variables
var hours:* = time.getHours();
var minutes:* = time.getMinutes();
var seconds:* = time.getSeconds();
var hourStrg:String;
var minuteStrg:String;
var secondStrg:String;
//time text
if(String(seconds).length < 2){
seconds = "0" + seconds;
}
if(String(minutes).length < 2){
minutes = "0" + minutes;
}
if(hours > 11){
ampm_txt.text = "PM";
} else {
ampm_txt.text = "AM";
}
if(hours > 12){
hours = hours - 12;
}
if (String(hours).length < 2){
hours = "0" + hours;
}
time_txt.text = hours + ":" + minutes + ":" + seconds;
}
Copy link to clipboard
Copied
this is approximate for a date countdown. it's simpler if you just want to countdown from say 60 seconds.
import flash.utils.Timer;
import flash.events.TimerEvent;
var futureTime:int = new Date(whateveryear,whatevermonth,whateverdate).time; //edit these 3 parameters
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);
function loopF(event:TimerEvent):void{
var t:int = Math.round(futureTime-new Date().time/1000);
if(t>0){
displayF(t);
} else {
looper.stop();
}
}
function displayF(t:int):void{
var d:Date = new Date(t);
time_txt.text = (t.fullYear-1970)+" years"+" "+t.month+" months"+" "+t.date+" days"+" "+padF(t.hours)+" hours"+" "+padF(t.minutes)+" minutes"+" "+padF(t.seconds)+" seconds";
}
function padF(i:int):String{
var s:String = i.toString();
while(s.length<2){
s+="0";
}
return s;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now