arrays in Flash
- Started
- Last post
- 11 Responses
- ukit
I have a number of objects I am reading in from XML into Flash. Each of these objects has a few attributes, and each one may have a set of subobjects, with the same set of attributes. I'm wondering, high-level, what's the best way to structure this data using arrays?
- joyride0
man bump this tomorrow i'll help you out... i'm heading out and i'm sure i'll be pretty much useless when i get back... plus will be occupying my time... lol
- mrbee28280
What I do is parse each node I need into an object with attributes. That gives me a 2D array that frees me of indexing like theArray[0][2] for something specific. With objects inside the array you can get anything like theArray[0].shirtSize etc.
theArray = new Array();
theShirt = new Object;// loop through xml
theShirt.size = node.attribute;
theShirt.color = node.attribute;theArray.push(theShirt)
// end loop
- ukit0
Thanks - that seems like a good solution for the first part, and more elegant than what I had. But I'm actually trying to add another level of complexity to it. What if, taking your example, each Shirt may (or may not) have one or more Button objects attached to it with its own set of attributes? What's the best way to handle that?
- ukit0
OK - I think I figured it out. One more question, if anyone knows - how do I create a new Array with a dynamic name?
For instance:
["comment"+i] = new Array();
returns an error.
- chimchim0
you need to specify scope first.
this["comment"+i] = new Array();
- jpea0
you could just start with xpath and forget all your worries
- tomkat0
why would you wanna do that?
you can access the xml directly (inside flash) like
myXML.firstChild.ChildNodes[i].a...
?
- urban100
an easier way to access xml nodes is to use the XMLShortcuts component:
- bigredmailbox0
node 3
- PonyBoy0
Enter response:
what tomkat said...
... set up your xml object...
... then it gets a lil tricky w/the parent... firstchild... nodebutt shit...
... yeah...
... hehe... but... BUT... if you take about 2 hours... get ROCKED on some coffee and a lil Iron Maiden... then... focus..
... i swear you'll get it and you'll be a rockstar at it.
(just try... please?)
- quik0
Loop through your XML, write it in to an associative array or a set of arrays.. then use it in your application.