Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Countdown to christmas ActionScripting help

New Here ,
Dec 02, 2011 Dec 02, 2011

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);

    }

}

TOPICS
ActionScript
912
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2011 Dec 02, 2011

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);

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2011 Dec 02, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 02, 2011 Dec 02, 2011

No dice..

I think it has something to do with the

var sunday = 0;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 03, 2011 Dec 03, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines