Skip to main content
Participant
August 9, 2006
Question

Loading XML into dynamic text boxes

  • August 9, 2006
  • 2 replies
  • 433 views
I have an XML document and I am trying to load the text from that doc into corresponding dynamic text boxes in flash. I wanted to use a loop to do this because I have 30+ textboxes to load text into and I thought this would be easiest to do. I know that the XML is being parsed and I can get it into the dynamic text boxes without the loop so I know the loop I'm trying to use is the problem. The dynamic text boxes are named "page1box0", "page1box1", "page1box2", etc. Here is my AS code (and I'm using Flash 8):


//create new xml object
xmlDoc = new XML();
//ignore white space in xml doc
xmlDoc.ignoreWhite = true;
//used this in a loop to ensure that xml doc loaded
xmlDoc.onLoad = function(success) {
if (success) {
//trace(this);
j=0;
while (j <= xmlDoc.firstChild.firstChild.firstChild.childNodes.length) {
currentXML = xmlDoc.firstChild.firstChild.firstChild.childNodes.firstChild.nodeValue;
trace ("currentXML = " + currentXML);
currentBlank = _root["page1box" + j + "_txt"];
trace ("j = " + j);
currentBlank = currentXML;
j++;
}
//trace ("currentXML = " + currentXML);
} else {
trace("xml not loaded");
}
};

This topic has been closed for replies.

2 replies

tbar1Author
Participant
August 10, 2006
Tried that one too with no success. When I trace "this...." it comes back undefined.
Inspiring
August 11, 2006
I still think it is a scope issue tbar1. You mentioned that when you trace the following;

trace ("this = " + this["page1box" + j].text);

…it comes back “undefined”? That tells me that the textfield is in the wrong place or the instance name is incorrect. If that doesn’t help you, if possible post the files online.
Inspiring
August 10, 2006
You mention that the instance name format are like the following;
"page1box0",
"page1box1",
"page1box2", etc.

But in your code your have;

currentBlank = _root["page1box" + j + "_txt"];

Notice the “_txt” suffix.
tbar1Author
Participant
August 10, 2006
I was using the _txt just to try and see if that would work. But I also tried:
_root["page1box" + j]

and that didn't work either. I should probably have mentioned that all of the text boxes are located in a movie clip, but all of the AS code is also in that same movie clip.
Inspiring
August 10, 2006
If I understand what you are saying then it’s a scope issue. Try;

this["page1box"+j]