Open a new file and give
it a name
date.fla.
Here we will display day and date in the format
[Day, date], for ex:- Sunday, 1 Jan. 2004.
So first of all select first frame, open script
window (F9), and write following code.
mydate = new Date();
day = mydate.getDay();
dt = myDate.getDate();
month = mydate.getMonth();
yr = mydate.getFullYear();
trace(day + " , " + dt + "
" + month + " " + yr);
|
When you test this movie, you will get some unexpected
result. This is because Flash action script returns
day of the week (0 for Sunday, 1 for Monday, and
so on) and Month (0 for January, 1 for February,
and so on) in Numeric format. To display date
in Understandable format we have to write some
more code for validation. This can be done by
a simple
if condition. So once
again open script window and add following code:-
if(day==0) {
day = "Sunday" ;
}
else if(day==1) {
day = "Monday" ;
}
else if(day==2) {
day = "Tuesday" ;
}
else if(day==3) {
day = "Wednesday" ;
}
else if(day==4) {
day = "Thursday" ;
}
else if(day==5) {
day = "Friday" ;
}
else if(day==6) {
day = "Saturday" ;
} |
Now you will see that the Day of the week is being
displayed in text format and not in numeric format.
Same validation need to be applied for month.
And now to show the date on stage, add a dynamic
text box with variable name "dtformat"
and set the formatted date in this variable, and
you have done it.