Core objects
Date object
In this lesson you will familiarize yourself with several Flash intrinsic objects – those which are supplied with Flash as a part of ActionScript Language for the convenience of the programmer.The first object you will learn about is Date
Date object is traditional for most computer languages. It is used to record, keep, format and display an information about date and time. Date object includes numerous methods which may be separated into two groups – Set and Get methods. As it can be presumed from the names, get methods are reading date and time from the existing Date objects, while set methods are writing (updating) date and time values for the Date objects.
When new Date object is newly created it is assigned the value of date and time from computer timer. Information is kept in milliseconds relative to local time and may be transferred to UTC (Greenwich) time if the time zone is installed correctly on the computer.
Let's create a small example.
- Make five dynamic textboxes and assign variables in Properties inspector day, weekday, month, year, fulldate . Add labels (static texts) with respective names.
- Enter the following code to the first and the only frame of the main movie timeline
today = new Date(); day = today.getDate(); weekday = today.getDay(); month = today.getMonth(); year = today.getFullYear(); fulldate = today.toString();
The first line of the code creates the new Date object, which by default is assigned the date of the computer and others format the date value extracting various information from the object. Month and day of the week are displayed as numbers from 0 (Sunday for day January for month).
- You also may extract hours, minutes, seconds from the Date by using respective methods such as getHour() and so on