Archive for April 2nd, 2005

Week 1 and 2: ActionScript Class

Download the week 1 and 2 sample files :

Week 1 & 2 presentation
Week01.zip
Week02.zip

Using the Date Object

Sometimes it is necessary to display information within Flash on certain days only, until a certain or only after a certain date has passed. This is a simple ActionScript test to set up todays date in the following format “YearMonthDate”. Example. 20050402 for today.

[as]
var testDate1 = “20050306″; // March 6th, 2005
var testDate2 = “20050406″; // April 6th, 2005

// create Date object
var now:Date = new Date();

// call Month, Day, and FullYear methods
var Month = now.getMonth() + 1; // Month is zero index, so add 1
var Day = now.getDate();
var Year = now.getFullYear();

// Add zero(0) to front of Month or Day if less than 10
Month = (Month< =9) ? "0"+Month : Month +""; // Month + "" is to force String
Day = (Day<=9) ? "0"+Day : Day + ""; // Day + "" is to force String

// combine into full string
var today:String = Year+Month+Day;

trace(today);

// simple test of testDate1
if (today >= testDate1) {
trace(“Today matches or exceeds the test date =>(“+testDate1+”).”);
} else {
trace(“Today is not quite enough. test date =>(“+testDate1+”).”);
}

// simple test of testDate2
if (today >= testDate2) {
trace(“Today matches or exceeds the test date =>(“+testDate2+”).”);
} else {
trace(“Today is not quite enough. test date =>(“+testDate2+”).”);
}
[/as]

Return top