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

How can I make a Day countdown timer in flash

Community Beginner ,
Apr 22, 2013 Apr 22, 2013

Here's my code, and below the code is the error message

// register function

addEventListener('enterFrame',daytimer_handler);

// calls repeatedly

function daytimer_handler(evt:Event):void{

// current date

var today:Date = new Date(2013, 4, 22);

// current Year

var currentYear = today.getFullYear(2013);

// current month

var currentMonth = today.getMonth(April);

// current day

var currentDay = today.getDate(Monday);// current time

var currentTime = today.getTime(12:00:00 PM);

// target date (5 days from now change to your need

var targetDate:Date = new Date(currentYear, currentMonth, currentDay+5);

var targetDay = targetDate.getTime(April/27/2013);

// time remaining

var timeLeft = targetDay-currentTime;

var sec = Math.floor(timeLeft/1000);

var min = Math.floor(sec/60);

var hours = Math.floor(min/60);

var days = Math.floor(hours/24);

// convert sec to string

sec = String(sec%60);

// if less than add a 0

if (sec.length<2) {

sec = "0"+sec;

}

min = String(min%60);

if (min.length<2) {

min = "0"+min;

}

hours = String(hours%24);

if (hours.length<2) {

hours = "0"+hours;

}

days = String(days);

if (timeLeft>0) {

// display day string

var dayCounter:String = days;

timer_display.text = dayCounter;

} else {

trace("Happy Birthday!");

var newTime:String = "0";

timer_display.text = newTime;

removeEventListener('enterFrame',daytimer_handler);

}

};

error message:

Description:

1084: Syntax error: expecting rightparen before colon.  

Source:

var currentTime = today.getTime(12:00:00 PM)

TOPICS
ActionScript
1.3K
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 ,
Apr 22, 2013 Apr 22, 2013

to be sure, that's a syntax error

if today is a date instance, use:

today.getTime();

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
LEGEND ,
Apr 22, 2013 Apr 22, 2013
LATEST

There are numerous syntax errors in your code, especially usage of Date methods - getFullYear, getMonth, etc. To begin with, this code should look like this:

import flash.events.Event;

// register function

addEventListener(Event.ENTER_FRAME, daytimer_handler);

// calls repeatedly

function daytimer_handler(e:Event):void

{

// current date

          var today:Date = new Date(2013, 4, 22);

// current Year

          var currentYear = today.getFullYear();

// current month

          var currentMonth = today.getMonth();

// current day

          var currentDay = today.getDate(); // current time

          var currentTime = today.getTime();

// target date (5 days from now change to your need

          var targetDate:Date = new Date(currentYear, currentMonth, currentDay + 5);

          var targetDay = targetDate.getTime();

// time remaining

          var timeLeft = targetDay - currentTime;

          var sec = Math.floor(timeLeft / 1000);

          var min = Math.floor(sec / 60);

          var hours = Math.floor(min / 60);

          var days = Math.floor(hours / 24);

 

// convert sec to string

          sec = String(sec % 60);

 

// if less than add a 0

          if (sec.length < 2)

          {

                    sec = "0" + sec;

          }

 

          min = String(min % 60);

          if (min.length < 2)

          {

                    min = "0" + min;

          }

          hours = String(hours % 24);

          if (hours.length < 2)

          {

                    hours = "0" + hours;

          }

          days = String(days);

          if (timeLeft > 0)

          {

// display day string

                    var dayCounter:String = days;

                    timer_display.text = dayCounter;

          }

          else

          {

                    trace("Happy Birthday!");

                    var newTime:String = "0";

                    timer_display.text = newTime;

                    removeEventListener('enterFrame', daytimer_handler);

          }

}

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