Results 1 to 7 of 7
-
October 8th, 2009, 02:00 PM #14Registered User
postspopulating 3d array from external xml
Hello! I have a short xml file. I want to populate it using some kind of loop inside an empty 3D array when the file loads, I want it to look like this:
Here's my XML file:Code:["LOL", "Laughing Out Loud", "0"], ["OMG", "Oh My God", "0"], ["BTW", "By The Way", "0"]
How can I do that?Code:<questions> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> </questions>
Thank you!
-
October 8th, 2009, 02:15 PM #2125Registered User
postsYou just need to nest your arrays. In your example above, your outer array will hold 3 arrays, each of the inner arrays will hold the values. One way you could manually duplicate what I mean using your above example is:
Code:var arr:Array = new Array(); arr.push(["LOL", "Laughing Out Loud", "0"]); arr.push(["OMG", "Oh My God", "0"]); arr.push(["BTW", "By The Way", "0"]); trace(arr[2][1]); //By The Way
-
October 9th, 2009, 07:12 AM #34Registered User
posts
-
October 9th, 2009, 07:40 AM #4125Registered User
postsYou just use loops. Use one loop for your parent elements and another loop to put the child elements into the parent arrays, all of which are stored in one master array.
-
October 9th, 2009, 07:42 AM #54Registered User
posts
-
October 9th, 2009, 08:05 AM #6125Registered User
postsSomething like this would work with the XML provided above:
Code:var xml:XML = <questions> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> <question> <short>What's the meaning of..</short> <meaning>the meaning</meaning> <sign>0</sign> </question> </questions>; var questions:Array = new Array(); for(var i:uint = 0; i < xml.question.length(); i++){ questions.push([xml.question[i].short, xml.question[i].meaning, xml.question[i].sign]); } trace(questions); //What's the meaning of..,the meaning,0,What's the meaning of..,the meaning,0,What's the meaning of..,the meaning,0
-
October 9th, 2009, 08:13 AM #74Registered User
posts

Reply With Quote


Bookmarks