PDA

View Full Version : Tricky XML AS3 question



alkrantz
November 2nd, 2009, 01:20 PM
At least tricky for me, perhaps one of you guru's will know the answer.

What I want to do in a nutshell: display the last node of an xml file first.

I am using AS3 to pull a dynamically created XML list based on date ranges and display 9 entries. The xml list that I am pulling is dynamically generated by an external vendor and I can not control it or format it. The XML feed contains several nodes with the most recent "entry" placed last in the node list. I need to display the last node first, essentially re-ordering the list from last to first.

Any ideas?

Thanks
-Aaron

senocular
November 2nd, 2009, 01:25 PM
Loop through it backwards... ? Is there something requiring that the order be in the order of appearance? Do you need to physically reorder the XML?

alkrantz
November 2nd, 2009, 02:50 PM
Hey Senocular,
Thanks for the response. My apologies if I seem a novice.


Loop through it backwards... ?

I assume you are referring to some kind of "for" loop, looping backwards through the XMLList. I'm not sure how to loop backwards through something.


Is there something requiring that the order be in the order of appearance? Do you need to physically reorder the XML?

Hopefully this will make sense.

I am using 3 text fields to display 3 nodes at a time from a dynamically generated XL file. In AS3 I am using an XMLList to store the XML. Every few seconds a timer calls a function that displays the next 3 nodes in the XMLList. This happens 2 times and recycles, so that a total of 9 nodes are displayed, and then they repeat.

The 9 nodes I am displaying are supposed to be the most recent entries into the XML, unfortunately they are not. The XML I am pulling from always has the latest entry as the last node. I don't know how that is being done because I did not create it and cant edit it. I assume they are using a php file to parse it somehow.

My conflict arises because the XMLList I have created in AS3 seems to store the nodes in the order they are written in the xml file, meaning the top node is the first entry and the second node is the second entry, etc. However, the xml file itself is adding the most recent entry as the last node. So when I display the first 9 entries of the XML it will be the OLDEST 9 entires and not the NEWEST. This is exactly the opposite of the behavior I would like.

To further complicate things I pull the xml using a date range which results in an xml file that can have varying lengths, anywhere between 20-50 nodes.

Hopefully that makes some sense. My apologies if I am confusing, it wouldn't surprise me because I am certainly confused. I have been using flash for many years and I am comfortable with AS3 but I am by training a designer, so I am sure there are concepts I do not fully understand.

Thanks again for any help
-Aaron

Scott64
November 2nd, 2009, 03:14 PM
I assume you are referring to some kind of "for" loop, looping backwards through the XMLList. I'm not sure how to loop backwards through something.

Example:


var numberOfItems:Number = 9;
for(var i:Number = numberOfItems-1; i >= 0; i--){
}

micken
November 2nd, 2009, 03:18 PM
Have you tried making a new XMLList out of the one you are pulling? I mean by getting 1 node at a time and inserting it at the beginning of the new list.

alkrantz
November 2nd, 2009, 03:48 PM
Example:


var numberOfItems:Number = 9;
for(var i:Number = numberOfItems-1; i >= 0; i--){
}



How obvious, I don't know why I didn't think of simply decrementing instead of incrementing the value of i. Thanks, I'm sure that will come in handy for me eventually. I am not sure it solves my problem in this case however.

alkrantz
November 2nd, 2009, 03:51 PM
Have you tried making a new XMLList out of the one you are pulling? I mean by getting 1 node at a time and inserting it at the beginning of the new list.

Hmmm. I have to think about how I would get this to work, could be a possibility.

efos
November 2nd, 2009, 04:19 PM
Hmmm. I have to think about how I would get this to work, could be a possibility.

Tip: Read your last two posts in reverse order.

internalXML.appendChild(externalXML.child(i))

Alternately, disregard the reverse loop and use prependChild()

amilazzo
November 2nd, 2009, 06:56 PM
i suppose you could run through all the xml entries and count them. once you have a number, go to that number xml entry. then count down going to all those xml entries until you get to 1, then stop