Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Loading XML into dynamic text boxes



Anggie Bratadinata
8/9/2006 9:33:32 PM
[quoted text, click to view]

Shouldn't it be :
currentBlank.text = currentXML ;
?
tbar1
8/9/2006 11:57:51 PM
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[j].firstChild.nodeValue;
trace ("currentXML = " + currentXML);
currentBlank = _root["page1box" + j + "_txt"];
trace ("j = " + j);
currentBlank = currentXML;
j++;
}
//trace ("currentXML = " + currentXML);
} else {
trace("xml not loaded");
}
};


myIP
8/10/2006 1:10:59 AM
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.

tbar1
8/10/2006 1:27:17 AM
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.
myIP
8/10/2006 1:30:57 AM
If I understand what you are saying then it?s a scope issue. Try;

this["page1box"+j]
tbar1
8/10/2006 4:25:38 AM
Thanks for the suggestion, unfortunately that didn't work either. I put in a
trace after the line:

currentBlank = _root["page1box" + j];
and the change you suggested:
currentBlank = this["page1box" + j];

and with both the var "currentBlank" came back undefined.
myIP
8/10/2006 12:17:46 PM
Ah?we forgot to add the .text property for the path. Also it seems to be that
Flash can?t have a dynamic path to be assigned to a variable and then have it
used else where. I thought that this would be possible with brackets, perhaps
I am wrong. However I got a simplified version from your code working;

j=0;
while (j <= 5)
{
currentXML = "stuff stuff stuff"+j;
trace ("currentXML = " + currentXML);

this["page1box"+j].text = currentXML;
j++;
}

But you might still have a scope looking at your last post.
So you have a movieclip on stage with roughly 30 textboxes inside of it,
correct?
And inside this movieclip you have the AS code in the timeline, correct?

If so then my previous post should be correct.

tbar1
8/10/2006 5:41:23 PM
Yes all of my text boxes are in a movie clip and all of the AS is in the movie
clip. So I tried the following:

j=0;
while (j <= xmlDoc.firstChild.firstChild.firstChild.childNodes.length) {
currentXML =
xmlDoc.firstChild.firstChild.firstChild.childNodes[j].firstChild.nodeValue;
trace ("currentXML = " + currentXML);
this["page1box"+j].text = currentXML;
trace ("this = " + this["page1box" + j].text);
//currentBlank = currentXML;
trace ("j = " + j);
j++;

And I also tried:

j=0;
while (j <= xmlDoc.firstChild.firstChild.firstChild.childNodes.length) {
currentXML =
xmlDoc.firstChild.firstChild.firstChild.childNodes[j].firstChild.nodeValue;
trace ("currentXML = " + currentXML);
currentBlank = this["page1box"+j];
currentBlank = currentXML;
trace ("currentBlank = " + currentBlank);
//currentBlank = currentXML;
trace ("j = " + j);
j++;

And neither of these worked.

everynewday
8/10/2006 6:05:18 PM
Would something like this work?

for (var j = 0; j <=
xmlDoc.firstChild.firstChild.firstChild.childNodes.length; j++) {
currentXML =
xmlDoc.firstChild.firstChild.firstChild.childNodes[j].firstChild.nodeValue;
trace ("currentXML = " + currentXML);
this["page1box"+j].text = currentXML;
trace ("this = " + this["page1box" + j].text);
//currentBlank = currentXML;
trace ("j = " + j);
}
tbar1
8/10/2006 6:15:39 PM
Anggie Bratadinata
8/10/2006 8:57:58 PM
tbar1,
What's the xml look like? Maybe you're targetting the wrong
node/element.
myIP
8/11/2006 1:06:08 AM
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.
AddThis Social Bookmark Button