Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
to be sure, that's a syntax error
if today is a date instance, use:
today.getTime();
Copy link to clipboard
Copied
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);
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now