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.

Put current Date on your Flash banners

How to align an object in Flash

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:

23 Responses to “Put current Date on your Flash banners”
  1. KRANEO says:

    ok.

  2. FireW@ll says:

    extreamly nice….thx a lot

  3. Faisal says:

    excellent i like that…..gr8 job…

  4. Pheello Rathaba says:

    Please can you help me with simple action script tutorials cause i dont know anything about Action

  5. Laszlo says:

    it works fine! thank you!

  6. Melissa says:

    Works great! Thank you!!

  7. SANDEEP says:

    It is Realy nice… it is good to learn actionscript… thanks and send more actionscript to all flash user.

  8. panamadream says:

    very nice!very usefull code.tnx alot!

  9. sachin says:

    good one! i’ll use it on my website.thanx

  10. Imdbman says:

    Great tutorial!!!!! It really works!!!!

  11. the_cool_guy says:

    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.

  12. Amin says:

    Thank you very much, it really works. i faced some problems at the begining but finaly it works.
    Thanks

  13. Kathy says:

    You have built a good websited

  14. Dan says:

    made it .All information on this site is represented for users. A site is

  15. lhuv says:

    I browse and saw you website and I found it very interesting.Thank you for the good work, greetings

  16. Timmy says:

    I have your site for its useful and funny content and simple design.e

  17. Robert says:

    I enjoyed your page. Keep up the good work! Feel free to visit my page. It\’s cool too.e

  18. Ron says:

    You guys do a wonderful job! Keep up the good work!!!o

  19. Ron says:

    Greetings!..

  20. jammarlibre says:

    I browse and saw you website and I found it very interesting.Thank you for the good work, greetings

  21. Ron says:

    Dear web-master ! I looked your site and I want to say that yor very well>

  22. Melissa says:

    I have been looking for sites like this for a long time. Thank you!a

  23. judy says:

    Nice site… Cool guestbook…

Leave a Reply