Flash: xml->array
- Started
- Last post
- 27 Responses
- snizl
I am pulling in an xml file to flash that containts a multitude of nodes. I need to set up arrays to pull values from certain sets of nodes but am getting a little lost. I am lost on how to pull out the specific values I need, then manipulate use the values to populate txt fields or attach mc's to the stage.
code: http://pastebin.coconut.se/?id=4…
Any help is appreciated! Thanks.
- quoo0
all those firstChild's are giving me a headache. you know you can assign them to a variable, right? Where is the prodlem occuring? Are all your traces working properly?
- quoo0
oh, don't you want nodeValue rather than nodeName?
- snizl0
Actually I need the nodeValue. After writing all of taht stuff out I realized that they need a firstChild appended to them then NodeValue. Is there a better way you can suggest that I structure it?
- quoo0
just... instead of using all those firstChild.firstChild.firstchild do
path = firstChild.firstchild.firstChild... or however many you need, then you can do path.firstChild instead of writing all that stuff out, it's a little overwhelming to look at;) you can do the same for childNodes, assign it to an array first, then resuse that array.
- snizl0
I'm going through the firstChild's right now and changing them.
Can you elaborate a little on how to set up arrays to pull certain info?
- quoo0
you should check this out, if you already haven't... it explains it far better than i can:)
- snizl0
Gona check that out right now. When rewriting the node paths were you thinking something like this?
level1Child = this.firstChild;
level2Child = level1Child.firstChild;
level3Child = level2Child.firstChild;
level4Child = level3Child.firstChild;
- quoo0
but basically, just assign myArray = path.childNodes... then you can use myArray[i].firstchild.nodeValue to iterate through the the nodes using a loop.
- quoo0
not really, you just seem to use this.firstchild.firstchild.first... an awful lot. it'd be easier to read your code if you assigned this to a variable, and reused the variable rather than r etyping the full path each time.
- kyl30
thank god for NT
- snizl0
yes, yes
- fugged0
you should look for Justin Walkins XML2AS class.
I'll see if I can dig it up.
It converts an XML document into a native AS object
- snizl0
Could you briefly explain what it does exactly?
- snizl0
Also, do u have or know where the help files are for that?
- snizl0
actually I just figured out what it is just not how to use the objects after the xml is parsed.
- fugged0
look here:
http://www.alien109.com/meh.txti just whipped that out, hope it ain't wrong. heh.
- snizl0
so now you can refer to stuff in terms of values instead of using first node/childNodes all of the time?
- fugged0
yeah. that's the beauty of it. it deserializes it into a native AS object so the dot syntax applies. makes coding much easier.
- snizl0
That's awesome. Now I just need to play around with it some more. Thanks for turning me onto this!