Copy link to clipboard
Copied
I'm trying to make a countdown clock and was following a tutorial online. Heres the link.
http://www.youtube.com/watch?v=XrTHOUqaS-o&feature=related
Good news! I have the clock working and it is counting down to Sunday like his. But I need it to countdown to christmas and I dont know enough about coding. I tried targetDate but since the coding wasnt setup for it, it didnt work. So any ideas would be great.
-----------------------------------------------------------------------------------------------------------------------------
stop();
var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countdownTimer.start();
function updateTimer(Event:TimerEvent):void{
var today:Date = new Date();
var year = today.getFullYear();
var dtsBegin:Date = new Date(year, 2, 13);
var dtsEnd:Date = new Date(year, 10, 6);
if((today >= dtsBegin) && (today <= dtsEnd)){
today.minutes -= 240;
}
else{
today.minutes -= 300;
}
today.minutes += (today.getTimezoneOffset());
var sunday = 0;
var s:int = 59 - today.seconds;
var m:int = 59 - today.minutes;
var h:int = 0 - today.hours;
var d:int = sunday - today.day;
if(s < 0){
s += 60;
m--;
}
if(m < 0){
m += 60;
h--;
}
if(h < 0){
h += 24;
d--;
}
if(d < 0){
d += 7;
}
var days:String = new String(d);
var hours:String = new String(h);
var minutes:String = new String(m);
var seconds:String = new String(s);
if(days.length < 2) days = "0" + days;
if(hours.length < 2) hours = "0" + hours;
if(minutes.length < 2) minutes = "0" + minutes;
if(seconds.length < 2) seconds = "0" + seconds;
var time:String = days + ":" + hours + ":" + minutes + ":" + seconds;
time_txt.text = time;
if(s + m + h + d <= 0){
countdownTimer.stop();
gotoAndPlay(2);
}
}
Copy link to clipboard
Copied
use:
stop();
var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countdownTimer.start();
function updateTimer(Event:TimerEvent):void{
var today:Date = new Date();
var year = today.getFullYear();
var dtsBegin:Date = new Date(year, 2, 13);
var dtsEnd:Date = new Date(year, 11, 25);
if((today >= dtsBegin) && (today <= dtsEnd)){
today.minutes -= 240;
}
else{
today.minutes -= 300;
}
today.minutes += (today.getTimezoneOffset());
var sunday = 0;
var s:int = 59 - today.seconds;
var m:int = 59 - today.minutes;
var h:int = 0 - today.hours;
var d:int = sunday - today.day;
if(s < 0){
s += 60;
m--;
}
if(m < 0){
m += 60;
h--;
}
if(h < 0){
h += 24;
d--;
}
if(d < 0){
d += 7;
}
var days:String = new String(d);
var hours:String = new String(h);
var minutes:String = new String(m);
var seconds:String = new String(s);
if(days.length < 2) days = "0" + days;
if(hours.length < 2) hours = "0" + hours;
if(minutes.length < 2) minutes = "0" + minutes;
if(seconds.length < 2) seconds = "0" + seconds;
var time:String = days + ":" + hours + ":" + minutes + ":" + seconds;
time_txt.text = time;
if(s + m + h + d <= 0){
countdownTimer.stop();
gotoAndPlay(2);
}
}
Copy link to clipboard
Copied
oops. i didn't realize how screwed that code was. use:
var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countdownTimer.start();
var today:Date = new Date();
var year = today.getFullYear();
var dtsEnd:Date = new Date(year, 11, 25);
var s = Math.round((dtsEnd.getTime()-today.getTime())/1000)
function updateTimer(Event:TimerEvent):void{
s--;
if(s>0){
time.text = formatTimeF(s);
} else {
time.text = "Merry Christmas";
countdownTimer.stop();
}
}
function formatTimeF(s:int):String{
var days:int = Math.floor(s/(60*60*24));
s -= days*60*60*24;
var hours:int = Math.floor(s/(60*60));
s -= hours*60*60;
var minutes:int = Math.floor(s/60);
s -= minutes*60;
return formatF(days)+"."+formatF(hours)+"."+formatF(minutes)+"."+formatF(s);
}
function formatF(s:int):String{
var returnS:String = String(s);
while(returnS.length<2){
returnS = "0"+returnS;
}
return returnS
}
// p.s. please mark helpful/correct responses, if there are any.
Copy link to clipboard
Copied
No dice..
I think it has something to do with the
var sunday = 0;
Copy link to clipboard
Copied
I got it to work by tweaking what you gave me
stop();
var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countdownTimer.start();
var today:Date = new Date();
var year = today.getFullYear();
var dtsEnd:Date = new Date(year, 11, 25);
var s = Math.round((dtsEnd.getTime()-today.getTime())/1000)
function updateTimer(Event:TimerEvent):void{
s--;
if(s>0){
time_txt.text = formatTimeF(s);
} else {
countdownTimer.stop();
gotoAndPlay(2);
}
}
function formatTimeF(s:int):String{
var days:int = Math.floor(s/(60*60*24));
s -= days*60*60*24;
var hours:int = Math.floor(s/(60*60));
s -= hours*60*60;
var minutes:int = Math.floor(s/60);
s -= minutes*60;
return formatF(days)+"."+formatF(hours)+"."+formatF(minutes)+"."+formatF(s);
}
function formatF(s:int):String{
var returnS:String = String(s);
while(returnS.length<2){
returnS = "0"+returnS;
}
return returnS
}
//Thank you so much
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more