Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : please help: dynamic textfield won't update; not the usual suspects


Ken Fine
9/18/2004 7:49:08 PM
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 () ;

Ken Fine
9/18/2004 9:11:03 PM
Thanks very much for the help, blenz, but I'm not sure that's really what
the problem is. Since the total that I want to write to item.itemLabel.ext
is calculated server-side where the XML is generated, it isn't necessary to
build a collection of the childnodes -- I just need to be able to grab the
last one in the list.

For one reason or another, my movie is letting me assign a value to the
dynamic text field the first time my function is run, but it isn't updating
on subsequent loops. Any ideas why?

Thanks.

The
[quoted text, click to view]

blenz
9/19/2004 3:31:14 AM
the errant code is this "

item.itemLabel.text = (menuItem.attributes.dns);

menuItem in this case is a collection of your childNodes.. as you defined in
an earlier line of code
menuItem = this.firstChild.childNodes;

you need to parse through the nodes to get into the individual childNodes
either by using

menuItem.attributes.dns)

or the nextSibling property

mandingo
9/19/2004 10:21:29 PM
I have had similar probs before... and whilst I will confess to not reading too
heavily into your problem and it may or may not work for you... ( I always
found it a messy way ) but what I would do was clear the existing value first...

var myTotal = rootElement.lastChild.attributes.total;
_level0.theTotal.text = "";
_level0.theTotal.text=myTotal;

And what made it worse for me was that it wasn't a persistent problem...
others would refresh normally...

not much help, but worth a last effort try.
cheers
AddThis Social Bookmark Button