Date Objects

I l @ ve RuBoard

Date Objects

Another type of object that is built in to Flash is the Date object. It helps to think of the Date object as a different type of variable altogether, like numbers and strings. Date objects represent a point in time.

The Date object is broken into seven parts : year, month, date, hour , minute, second, and millisecond. You can create a new date object by supplying all these elements:

 myDate = new Date(2002,3,29,10,30,15,500); 

If you want to examine the contents of myDate with a trace command, you will get a string in the Output window that looks like this:

 Mon Apr 29 10:30:15 GMT 

This is easy to read and understand, but one odd thing sticks out: the month is Apr . But in the previous line, the month was set to 3. Shouldn't that be March?

Date objects in Flash work like Date objects in other computer languages. Most of them share the idiosyncrasy that months are numbered 0 to 11. This is strange because days of the month are numbered 1 to 31. It is just something you have to get used to.

You can get the components of a Date object by using one of a whole list of Date object functions. For instance, to get the year, you can use myDate.getYear() .

If you want to get the current time, all you need to do is create a blank Date object. The current time will be inserted. Try this in a frame of a blank movie:

 myDate = new Date(); trace(myDate); 

Flash gets the current date from the clock in the user 's machine. It is always a mistake to assume that this time is correct. Many users do not have their clocks set correctly. You can use this time and date for normal movies, but nothing critical like e-commerce or account transactions.

I l @ ve RuBoard

Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272 © 2008-2017.
If you may any questions please contact us: