It’s nice to have displayed current date on your website. A way to do this is to fit in a Flash banner. In this tutorial I will show you how you can display date in the format Wednesday, September 19, 2007 using ActionScript language.
STEPS TO FOLLOW:
1. Create a new flash 8 document about 450×50 pixels. Insert one more layer and then rename the bottom layer display and the top one actions.
2. In the first frame of the display layer draw a text field using the Text tool from the Tools panel. Select it, go to the Properties panel where you have to select Dynamic Text as Text Type and set font Arial, size 15, color #990099, align center. Give it also an instance name of displayDate_txt. While the text field is still selected go to the Align panel and center it both horizontal and vertical.
3. Let’s have some ActionScript now :). Go to the first frame of the actions layer, open the Actions panel (F9) and the following ActionScript code in:
var currentDate=new Date();
var weekDay=currentDate.getDay();
var weekDay_string:String;
var year=currentDate.getFullYear();
var month=currentDate.getMonth();
var month_string:String;
var numberDay=currentDate.getDate();
var numberDay_string:String;/* I use numberDay_string variable for adding a 0 before the days between 1 and 9. It's look better this way. */if (numberDay<10){
numberDay_string="0"+numberDay;
}else{
numberDay_string=numberDay;
}
/* I use a swich-case block for displaing months by their name, as everybody know them. ActionScript see them like numbers between 0 and 11, starting with January */
switch (month){
case(0):month_string="January"; break;
case(1):month_string="February"; break;
case(2):month_string="March"; break;
case(3):month_string="April"; break;
case(4):month_string="May"; break;
case(5):month_string="June"; break;
case(6):month_string="July"; break;
case(7):month_string="August"; break;
case(8):month_string="September"; break;
case(9):month_string="Octomber"; break;
case(10):month_string="November"; break;
case(11):month_string="December"; break;
}
/* I use a swich-case block for displaing days of the week by their name. ActionScript see them like numbers between 0 and 6, starting with Sunday*/
switch (weekDay){
case(0):weekDay_string="Sunday"; break;
case(1):weekDay_string="Monday"; break;
case(2):weekDay_string="Tuesday"; break;
case(3):weekDay_string="Wednesday "; break;
case(4):weekDay_string="Thursday"; break;
case(5):weekDay_string="Friday "; break;
case(6):weekDay_string="Saturday"; break;}
/* display the date in the desired way*/
displayDate_txt.text=weekDay_string+", "+month_string+" "+numberDay_string+", "+year;
We finished our job! Test the movie Control >> Test Movie (or Ctrl+Enter) and the result should look like the one below:



Entries (RSS)
December 13th, 2007 at 12:15 pm
ok.
December 20th, 2007 at 11:21 am
extreamly nice….thx a lot
January 1st, 2008 at 9:52 pm
excellent i like that…..gr8 job…
January 8th, 2008 at 5:20 am
Please can you help me with simple action script tutorials cause i dont know anything about Action
January 9th, 2008 at 8:16 am
it works fine! thank you!
January 17th, 2008 at 11:51 am
Works great! Thank you!!
January 17th, 2008 at 11:29 pm
It is Realy nice… it is good to learn actionscript… thanks and send more actionscript to all flash user.
February 13th, 2008 at 6:47 pm
very nice!very usefull code.tnx alot!
February 19th, 2008 at 5:28 am
good one! i’ll use it on my website.thanx
February 23rd, 2008 at 3:16 pm
Great tutorial!!!!! It really works!!!!
April 6th, 2008 at 12:49 pm
Wow what a beautiful story. I have read your blog for a long time and have never posted a comment…It is no wonder that you often don’t open up comments with all the wack jobs out in this world.