I have a Flash MP3 player that loads the song list from an XML file. I'm trying
to set it up to take the customer to the online store to purchase the currently
playing song. The player successfully loads the track name, artist name, and
url to the song, but for some reason does not appear to the load the new
attribute of buylink that I have just added. Given the code below, my buylink
value is returned as undefined. Can anyone tell me where my error is here? If
more info is needed please let me know!
The xml file reads as this for each song:
<?xml version="1.0" encoding="UTF-8"?>
<songs>
<song url="http://mywebsite.com/music/filename.mp3" artist="Artist Name"
track="Track Name"
buylink="http://mywebsite.com/store/index.php?cPath=21_29&sort=2a&action=buy_now
&products_id=69" />
</songs>
The code in flash to load the array reads:
// Load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
var nodes:Array = this.firstChild.childNodes;
for(var i=0;i<nodes.length;i++)
{
sa.push(new Song(nodes[i].attributes.url, nodes[i].attributes.artist,
nodes[i].attributes.track, nodes[i].attributes.buylink));
// iterate through mp3 array, and add mp3s to the listbox
mp3List.addItem(nodes[i].attributes.track, nodes[i].attributes.buylink);
}
}
xml.load("songs.xml");
And the Song Class file is:
class Song
{
public var earl:String;
public var artist:String;
public var track:String;
public var buylink:String;
public function Song(e:String, a:String, t:String, b:String)
{
earl = e;
artist = a;
track = t;
buylink = b;
}
}
Raymond Basque - 18 Jun 2007 13:02 GMT
Have you checked the validity of that XML file? Simplest way is to open it
with a browser.
kllwca - 18 Jun 2007 18:47 GMT
Aha.
XML Parsing Error: not well-formed.
It appears to have issues with the = signs in the link. This is a problem for
my site, as I need those in there in order to link to the page. I'll have to
come up with something other than xml for the 'add to cart' functionality
within this flash file.
Oddly enough, it does pick up all of the rest of the information.
Thanks.
kllwca - 18 Jun 2007 20:16 GMT
The problem with my XML file has now been resolved (had to escape the
ampersands), but I'm still getting undefined for that attribute.
A note - within Flash, all of my attributes show up as blue text in the .as
except for the one that is not working. Eg, in the lines above,
attributes.track is blue; attributes.buylink - attributes is blue, buylink is
black.