Arrays and date

Hi there,

I am pretty new with Actionscript (on the border of stupidity ;))I wonder if you guys can help.

I am trying to display items on a array depending on certain date of the month ( july 1st: text1, july 2nd: text 2, etc, etc.)

Now, this is my actual code:

var currentDate:Date = new Date();
var indexPosition = currentDate.getDate();
var textForToday = julyArr[indexPosition];

var julyArr:Array = new Array();

julyArr[0] = “Text for the 1st of July”;
julyArr[1] = “Text for the 1st of July”;
julyArr[2] = “Text for the 2nd of July”;
julyArr[3] = “Text for the 3rd of July”;

date_txt.text=textForToday;

But when I test my movie it returns undefined

Any clues???

Thank guys.

You’re calling the indexPosition for julyArr before you’ve created the array. That’s why it’s undefined.

It will also return an undefined value for any date that’s greater than 3 unless you add more elements to the array.

Finally, you might want to change it slightly so that indexPosition is currentDate.getDate()-1; to avoid having to duplicate the first two elements of your array. Try this:

// create array
var julyArr:Array = new Array();
julyArr[0] = "Text for the 1st of July";
julyArr[1] = "Text for the 2nd of July";
julyArr[2] = "Text for the 3rd of July";
julyArr[3] = "Text for the 4th of July";
// continue to julyArr[30] = "Text for the 31st of July";
julyArr[30] = "Text for the 31st of July";
// retrieve current date
var currentDate:Date = new Date();
// set index position == date - 1
var indexPosition = currentDate.getDate()-1;
// assign date element of array to date_txt
var textForToday = julyArr[indexPosition];
date_txt.text=textForToday;

glosrfc,

It worked beautifuly, thank you sooooo much for your help.