I am trying to create a new ActionScript 3.0 file in Flash that will include the Current Time, Date and Day of the week. I am able to complete the script separately (Time and Date) and (DayofWeek) but when combining I receive line errors 1120:Access of undefined property time. I am not a GURU but am a pretty fast learning. I would appreciate any help that can be provided to me. Also I would like for the time to display AM\PM and to show in double digits for numbers ranging from 1-9 with a "0" added. Thank you in advance
Here is my code below
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, looptime)
function looptime(event:TimerEvent):void{
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var today_date:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();
var day_str:String = dayOfWeek_array[today_date.getDay()];
var hour:Number = time.getHours();
var minute:Number = time.getMinutes();
Day_txt.text = day_str;
Date_txt.text = month + "-" + day + "-" + year;
if (hour > 12){
Time_txt.text = hour-12 + ":" + minute;
}else if (minute < 10){
Time_txt.text = hour + ":" + "0" + minute;
} else {
Time_txt.text = hour + ":" + minute;
}
//Time_txt.text = hour + ":" + minute;
}
your coding has some little problems.for example you don't need to define
dayOfWeek_array
every second.this makes your app slow.so put it out of yourlooptime
function.and better to useuint
type instead ofNumber
for variables that won't contain decimal numbers.This is the full code(AM/PM system).you can copy this:
Hope this helps.☺