I know that most of you know how to do this, however I've never tried, and don't really understand how the book explains it.
I have an XML file filled with strings I need to use in flash.
(with all the "["'s replaced with "<"'s)
[TEXT]This is one[/TEXT]
[TEXT] This is two[/TEXT]
Now what I want to do is to dynamically load randomlly load one of these strings into my dynamic text box!
Can someone explain how to randomally get the strings from the xml? mostly how to get them though, I can do the random stuff.
Thanks in advance!!
You'll probably like using the childNodes property/array.
For instance:: (using your XML file...)
nameOfXMLObj = new XML;
firstText = nameOfXMLObj.childNodes.childNodes.childNodes;
secondText = nameOfXMLObj.childNodes.childNodes.childNodes;
thirdText = nameOfXMLObj.childNodes.childNodes.childNodes;
So you get the idea... childNodes is an array like property.. I'm not sure how to describe it... use it like an array by accessing items in it's 'list' with  operators... and it can be placed after a node, to access that nodes children...
So Parent.childNodes would give you child3.... I hope this is making sense.... Look under childNodes in the Flash help files...
OH - and as always, don't forget to deal with the elusive 'whitespace nodes'.... they will also show up on the childNodes array...
As for your randomness.. just randomise the number inside the brackets, make sure that it isn't over the parent.childNodes.length property of your array....
Thank you very much for your help,
I appreciate it!
also, just as a question if I have a file like this:
I can access it by using:
quotes = new XML();
ran = random(142);
display = quotes.childNodes.childNodes[ran];
Will that work? - I've been having some problems with it.
Yeah.. you've got the idea - you'll want to mess around with the number of childNodes tags you'll need to access certain levels of code.. due to whitespace...
Click Here to Expand Forum to Full Width
Poll by Flashkit.com