Been knocking my head on this for awhile, and hoping someone can help. I've
made a script that retrieves XML from a remote address and parses it at a
six-second intervals. I'm having trouble making it update a dynamic
textfield on the stage -- the first update happens, but no further updates
occur even though a look at "trace" suggests changing data.
The xml looks something like this
<whatever>
<item dns="whatever.com" total="1">
<item dns="whoever.org" total="2">
....
</whatever>
The "total" attribute is a simple count of the nodes that's generated by the
server that's creating the XML. (sloppy, I know, but I'm just experimenting
here.)
I'm trying to use the final "total" attribute to update a dynamic textfield.
As I said earlier, this update happens in the first iteration, but doesn't
subsequently change, even though I can see additional nodes being added to
the XML document in by a seperate server-side process.
Can someone have a look at my code below and tell me what's going on? I wrap
the XML retrieval in a function, remembering to randomize the URL of the
retrieved XML. Toward the end of that process, I attempt to grab the total:
and assign it to dynamic textfield on the stage:
var myTotal = rootElement.lastChild.attributes.total;
_level0.theTotal.text=myTotal
I then set an interval and call that function at six-second increments. But
the initial number is never updated.
Ideas?
Thanks...
-KF
my_xml = new XML( );
function getMyStuff () {
unique = Math.round(Math.random()*10000);
my_xml.load("
http://myURL.asp?stuff="+unique);
my_xml.ignoreWhite = true;
my_xml.onLoad = function (success) {
if (success) {
// trace("The XML was successfully parsed. Here are the contents: ");
menuItem = this.firstChild.childNodes;
trace (menuItem);
var itemCounter=1
for (var i=0; i<menuItem.length; i++) {
itemCounter= itemCounter+1
item = _root.attachMovie("itemClip", "itemClip" + i, i);
item._x = 100 ;
item._y = 10 *i;
item.itemLabel.text = (menuItem[i].attributes.dns);
trace (menuItem[i].attributes.dns);
}
rootElement = my_xml.firstChild;
aElement = rootElement.firstChild;
var myTotal = rootElement.lastChild.attributes.total;
_level0.theTotal.text=myTotal
} else {
trace("There was an error parsing the XML data");
}
};
}
//end function getmystuff
fetchStuffInterval = setInterval (getMyStuff, 6000);
fetchStuffInterval () ;