0
votes

I have 6 dynamic text fields & I want to add text in them from an xml file.

This code works:

titleTxt1.text = xmlListMain.children()[0].title;

But in a loop there is a problem:

for (var i:Number = 0; i < xmlListMain.children().length(); i++) {
    titleTxt[i].text = xmlListMain.children()[i].title
}

titleTxt[i].text is the part i get the error. How can I fix this?

1

1 Answers

0
votes

if your first textfield is named titleTxt0.text (ie your numbering starts with 0):

for (var i:Number = 0; i < xmlListMain.children().length(); i++) {
    this['titleTxt' + i].text = xmlListMain.children()[i].title;
}

if your first textfield is named titleTxt1.text (ie your numbering starts with 1):

for (var i:Number = 0; i < xmlListMain.children().length(); i++) {
    this['titleTxt' + (i + 1)].text = xmlListMain.children()[i].title;
}

Better to start your numbering with 0 for things like this so you can omit the extra step of adding 1 to the loop's index.