
Posted by Matthew David
When you are working with Flash you are working with time. The following ActionScript allows you to see the time you are working with.
Coding around the clock.
One of the weird things you have to look forward to as a developer is odd hours. I do not mean you do not fill in the 9-5 hours during the day - you still do those - but you also add to your list the weird hours. Yep, you will work until 2 in the morning. Not because you are being paid to (well, that can help) but because there is a weird passion in this business that drives us all.
Back in the 80's before the boom of the 'net and during a time when it was still "geeky" to be a programmer, Apple would hand out T-shirts to anyone who work more than 96 hours in a week! It seems insane, but you will find that you will hit that project that add passion to your work and you will hit those insane hours.
With that said, you will need to know what time of day it is when you do write code during those weird hours.Well, why not use your ActionScript date functions to find out the time.
The following scripts allows your to find the current time, short date and long date formats. The trick to this script is to create a movie clip with two frames. All of the ActionScritp is placed in the first frame of the movie clip.
days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday');
months = new Array('January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December');
timedate = new Date();
hour = timedate.getHours();
minutes = timedate.getMinutes();
seconds = timedate.getSeconds();
todaydate = timedate.getDate();
day = timedate.getDay();
dayname = days[day];
month = timedate.getMonth();
monthname = months[month];
year = timedate.getFullYear();
if (length(minutes) == 1) {
minutes = "0"+minutes;
}
if (length(seconds) == 1) {
seconds = "0"+seconds;
}
delete timedate;
timedate = new Date();
createTextField("timeNow", 1, 100, 100, 400, 200);
timeNow.multiline = true;
timeNow.wordWrap = true;
timeNow.border = false;
myformat = new TextFormat();
myformat.color = 0x333333;
myformat.bullet = false;
myformat.underline = false;
myformat.font = "Verdana";
timeNow.text = "24 Hour Clock: "+hour+":"+minutes+":"+seconds;
timeNow.setTextFormat(myformat);
createTextField("shortDate", 2, 100, 125, 200, 200);
shortDate.multiline = true;
shortDate.wordWrap = true;
shortDate.border = false;
shortFormat = new TextFormat();
shortFormat.color = 0x333333;
shortFormat.bullet = false;
shortFormat.underline = false;
shortFormat.font = "Verdana";
shortDate.text = "Short Date: "+todaydate+"/"+month+"/"+year;
shortDate.setTextFormat(shortFormat);
createTextField("longDate", 3, 100, 150, 300, 200);
longDate.multiline = true;
longDate.wordWrap = true;
longDate.border = false;
longFormat = new TextFormat();
longFormat.color = 0x333333;
longFormat.bullet = false;
longFormat.underline = false;
longFormat.font = "Verdana";
longDate.text = "Long Date: "+dayname+" "+todaydate+" "+monthname+" "+year;
longDate.setTextFormat(longFormat);