-
Hello all,
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.
ex:
Code:
[XML]
[MAIN]
[TEXT]This is one[/TEXT]
[TEXT] This is two[/TEXT]
... continued
[/MAIN]
[/XML]
(with all the "["'s replaced with "<"'s)
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!!
-
Ok...
You'll probably like using the childNodes property/array.
For instance:: (using your XML file...)
nameOfXMLObj = new XML;
nameOfXMLObj.load("yourXMLFile.xml");
firstText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[0];
secondText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[1];
thirdText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[2];
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...
Parent
child1
child2
child3
/Parent
So Parent.childNodes[2] 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:
(quotes.xml)
I can access it by using:
Code:
quotes = new XML();
quotes.load(quotes.xml);
ran = random(142);
display = quotes.childNodes[0].childNodes[ran];
???
Will that work? - I've been having some problems with it.
Thanks again!
-
Ok...
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|