PDA

View Full Version : [AS3] Name-day screensaver, Array problem


LostMind
01-03-2012, 10:17 AM
Hello!

This is my first post in the year 2012, and I would like to say for everyone Happy New Year!

I want to make a flash screensaver with a name-day function, but when I want to print out the current name, I came to this error message:
ReferenceError: Error #1069: Property 2 not found on String and there is no default value.

Herre is my code(I only copy the January month):
var Jan:Array = new Array("","ÚJÉV","Ábel","Genovéva","Titusz","Simon",
"Boldizsár","Attila","Gyöngyvér","Marcell",
"Melánia","Ágota","Ernő","Veronika",
"Bódog","Lóránt","Gusztáv","Antal","Piroska",
"Sára","Sebestyén","Ágnes","Vince","Zelma",
"Timót","Pál","Vanda","Angelika","Károly,","Adél","Martina",
"Marcella");


var month_name:Array = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

var myDate:Date = new Date();
var cmonth_name = month_name[myDate.month];
var cday = myDate.day;

trace (myDate);
trace ("month name: "+month_name[myDate.month]);
trace ("day in number: "+cday);
trace ("name-day: "+cmonth_name[cday]);//this line not working

Oh, yes, and I want the current name-day to display a dynamic text field, let say it's name is: txt_nameday

Can anyone help? Please can anyone repaire my code?

solisarg
01-03-2012, 11:35 AM
cmonth_name is a String, say Jan, so cmonth_name[cday] make no sense, probably you need an array of days to target the week day

Jorge

LostMind
01-03-2012, 12:54 PM
Thanks

But why would I need an array of days, the days number i got with the myDate.day variable and this is the pointer in tha months array.

I feeezed at this point :-/

solisarg
01-03-2012, 12:59 PM
var cmonth_name = month_name[myDate.month];

This is i.e "Feb"

var cday = myDate.day;

This is i.e 2

So try now this

var a:String = "Feb"
var b:Number = 2;
trace(a[b])

Look at the error. Get the point?

Jorge

LostMind
01-03-2012, 01:15 PM
It's the same error, right?

so somehow I must put the month in numeric array?

LostMind

OK i found what was the problem! I copy the good source to help in the near future:

Now this works:

var Jan:Array = new Array ("","ÚJÉV","Ábel","Genovéva","Titusz","Simon",
"Boldizsár","Attila","Gyöngyvér","Marcell",
"Melánia","Ágota","Ernő","Veronika",
"Bódog","Lóránt","Gusztáv","Antal","Piroska",
"Sára","Sebestyén","Ágnes","Vince","Zelma",
"Timót","Pál","Vanda","Angelika","Károly,","Adél","Martina",
"Marcella");

var month_name:Array = new Array (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec) ;

var myDate:Date = new Date();
var cmonth_name = month_name[myDate.month];
var cday = myDate.day;

trace (cmonth_name[cday]);

The problem was in the row: var month_name:Array = new Array (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec) ;

I put the variables in quotation marks, but now it's working

thanks Jorge for your help :)

LostMind