PDA

View Full Version : Dynamic Text Fields with variable name


et_needHelp
03-02-2005, 06:30 AM
Hi All,

I am creating a dynamic calendar.

I have a number of dynamic text fields (approximately 31) each with a different instance name. This will be used to display the date for a particular day. The first text field is named date_1, the second text field is named date_2, the third date_3 etc until you get to date_30 being the 30th dynamic text field on screen.

What I would like to do is populate each field dynamically dependant on the Month we are in. For example in one month the 1st of the month will occur in field date_6, then the 2nd of the same month will be date_7.

This is my code. (Well the snippet that is trying to populate the text fields.) In this snippet I am assuming date_1 will be display the 1st.

_global.iDate = 1;
while (_global.iDate < 32) {
_global.varDate = "date_"+iDate;
textDate = _global.varDate;
_root.calendar.textDate.text = _global.iDate;
_global.iDate = _global.iDate + 1;
trace (textDate);
}
The problem I think lies in the red part of the code. As the tracing is working fine. It seems Flash is looking for a text field named textDate, rather than using the variable textDate set up previously.

If anyone can help with this (thats if you understand what I have said...I dont really know how to explain.)

Cheers

tGP
03-02-2005, 06:47 AM
you need it to look for the value of the variable textDate, not use that as the actual path...

try this:

_global.iDate = 1;
while (_global.iDate < 32) {
_global.varDate = "date_"+iDate;
textDate = _global.varDate;
_root.calendar["textDate"].text = _global.iDate;
_global.iDate = _global.iDate + 1;
trace (textDate);
}


cheers
j

et_needHelp
03-03-2005, 12:04 AM
Thanks tgp. Problem fixed. I knew it was just a lack of knowledge in syntax. Lesson Now Learnt!

Cheers :D