1. Computing & Technology

Discuss in my forum

ActionScripting Basics: Basic Date Functions

By , About.com Guide

Lump it all together inside an encompassing pair of parentheses, and you’ve got a solid string.

So why that pesky little “+1” in (today.getMonth() + 1)? Weeeeell, that’s just an oddity of Flash’s. It returns a 0 for January, 1 for February, 2 for March, etc.--like many scripting languages, it starts labeling/counting at 0, instead of at one. If you leave it as-is, then you’ll actually display the date for the current day, but last month. Adding the +1 will cause the value returned to reflect the current month.

Now for the last line:

_root.textdisplay.text="Today's date: "+dateTextField;

This is a variation of what we covered in the lesson on passing fetched values to a named dynamic text box, and will pass the string put together for variable dateTextField to the text box that we created at the start of the lesson, along with whatever text we specify.

My little date display movie is here.

©2012 About.com. All rights reserved.

A part of The New York Times Company.