Copy link to clipboard
Copied
Hello, I know this may be very basic, so I apologize in advance for that, but I just can´t figure it out after a couple of hours of Google it, so if anyone can help me, that would be great! Thanks in advance!
I have three dynamic text fields in my stage, called txt1, txt2 and txt3.
I want to put some data in them, but I want to find them using a variable:
var i: int = 1;
while (i < 4)) {
var textTemp : String = i.toString();
textTemp = "txt" + textTemp;
trace(textTemp); // So far, so good: in the Console, I get txt1, txt2 and txt3
i++;
// Now, lets say I want to set each text field to any text, it doesn´t really matter. So I try this:
textTemp.text = "This is a test"; // This didn´t work
TextField[textTemp].text1 = "This is a test"; // Neither this
}
Thanks again, I´m really lost here!
use array notation to coerce strings into objects:
var i: int = 1;
while (i < 4)) {
var textTemp : String = i.toString();
textTemp = "txt" + textTemp;
trace(textTemp); // So far, so good: in the Console, I get txt1, txt2 and txt3
i++;
// Now, lets say I want to set each text field to any text, it doesn´t really matter. So I try this:
this[textTemp].text = "This is a test";
}
Copy link to clipboard
Copied
use array notation to coerce strings into objects:
var i: int = 1;
while (i < 4)) {
var textTemp : String = i.toString();
textTemp = "txt" + textTemp;
trace(textTemp); // So far, so good: in the Console, I get txt1, txt2 and txt3
i++;
// Now, lets say I want to set each text field to any text, it doesn´t really matter. So I try this:
this[textTemp].text = "This is a test";
}
Copy link to clipboard
Copied
Work like a charm, thank you, kglad, I was driving myself crazy with this!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now