Hi,
I’m trying to load song info into flash. This radiostation has xml that is constantly being update according to previous, current and next song to be played. Here is the link to the xml:
internetradio (dot) vrt (dot) be /internetradio_master/productiesysteem2/song_noa/noa_41.xml
(where item index="-1" is the previous song, “0” is the current and “1” is the next song)
I got the following code and it works:
var RandNum:int
RandNum = Math.floor(Math.random() * (1+500000-10)) + 10;
trace(RandNum);
var urlRequest:URLRequest = new URLRequest("http://internetradio.vrt.be/internetradio_master/productiesysteem2/song_noa/noa_41.xml?" + RandNum);
var urlLoader:URLLoader = new URLLoader();
var xml:XML;
var xmlList:XMLList;urlLoader.load(urlRequest);
urlLoader.addEventListener(Event.COMPLETE,urlLoaded);
function urlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
txt_Previous.text = xmlList[0].artist.artistname + " - " + xmlList[0].title.titlename;
txt_Current.text = xmlList[1].artist.artistname + " - " + xmlList[1].title.titlename;
txt_Next.text = xmlList[2].artist.artistname + " - " + xmlList[2].title.titlename;
}
However, there are not always 3 items in the xml. Sometimes there wil only be item index="-1" and item index=“0” or item index=“0” and item index=“1”.
So if I ask for xmlList[2] it does not exist and flash gives an error
How can I check if an item with an index of -1, 0 or 1 exists ?
Here are two examples of the xml
**two items
**
<noa>
<item index="-1">
<itemcode/>
<title>
<titlename>no music</titlename>
</title>
<artist>
<artistname/>
</artist>
</item>
<item index="0">
<itemcode>S029711</itemcode>
<title>
<titlename>I need air</titlename>
</title>
<artist>
<artistname>MAGNETIC MAN</artistname>
</artist>
</item>
</noa>
three items
<noa>
<item index="-1">
<itemcode/>
<title>
<titlename>no music</titlename>
</title>
<artist>
<artistname/>
</artist>
</item>
<item index="0">
<itemcode>S029695</itemcode>
<title>
<titlename>Ready to start</titlename>
</title>
<artist>
<artistname>ARCADE FIRE</artistname>
</artist>
</item>
<item index="1">
<itemcode>S023253</itemcode>
<title>
<titlename>As long as it takes</titlename>
</title>
<artist>
<artistname>ISBELLS</artistname>
</artist>
</item>
</noa>