Skip to main content
Inspiring
October 31, 2008
Question

loading XML node into an Array

  • October 31, 2008
  • 2 replies
  • 421 views
greetings all,

i'm trying to load a node from an xml page into an array.
i can get the xml to load but i can't get the node into the

_streamList.push( { path:"PLAYLIST.SRC_NODE", bitrate:800 } );

i can get the file to load with a direct path "no xml"
_streamList.push( { path:"mp4:videofile.mp4", bitrate:800 } );

any help or advice would be a great help.

this is what i've got so far



thank for your help
cheers
This topic has been closed for replies.

2 replies

rob day
Community Expert
Community Expert
November 1, 2008
You might also consider using XML attributes, which might be a simpler approach than pushing an object into an array.

So if your XML looked something like this with a single child:

<playlist>
<song desc="title 1" src="mp4:Trailer_HD1.mp4" thumb="thumbs/tumb1.jpg" brate="800"/>
<song desc="title 2" src="mp4:Trailer_HD2.mp4" thumb="thumbs/tumb2.jpg" brate="800"/>
<song desc="title 3" src="mp4:Trailer_HD3.mp4" thumb="thumbs/tumb3.jpg" brate="800"/>
<song desc="title 4" src="mp4:Trailer_HD4.mp4" thumb="thumbs/tumb4.jpg" brate="800"/>
</playlist>

Now you can treat the XMLList itself as an array of objects. So:

trace (xmlList[0].@desc);//returns title1
trace (xmlList[2].@src);//returns mp4:Trailer_HD3.mp4
etc.
rob day
Community Expert
Community Expert
November 1, 2008
Try declaring an XMLList varaible at the top:

public var xmlList:XMLList;

Then set that to the xml's children:

xmlList=loadPlaylist.children();

Now you have an array of elements in the xml's children

trace (xmlList[1]);//returns mp4:Trailer_HD.mp4

If there were more than one child in your xml then

trace (xmlList[1].children()[1]);//returns the second element of the second child