PDA

View Full Version : How to load an image with variable


jasonrhl
01-15-2008, 03:03 AM
We cant get an image to show on our flash app.

We have a streaming radio station that creates and xml file which we grab album name , track and artist info from the id3 tag.

We are trying to show the album art.

We are hoping someone can tell us what we are doing wrong.
the example we are trying to get the album bum to bring up an image cali.jpg when it is in the xml file. We just get a blank space where the art should be (no errors)

// The first step is to activate the XML object
headlineXML = new XML();
xml.onLoad = function() {
//the methods to handle the xml
}

headlineXML.onLoad = myLoad;
headlineXML.load("/headlines.xml");

var intervalID = setInterval(this, "loadXML",1*10*1000);

/*
With the XML Object now active you must now load an XML foramtted document.
Any DTD or XLS formatting will be ignored.
*/
function loadXML() {
headlineXML.onLoad = myLoad;
headlineXML.load("headlines.xml");
}

// Before proceeding to far into the program, make sure the XML document has loaded
// Extract information from the XML file
function myLoad(ok) {
if (ok == true) {
Publish(this.firstChild);
}
}

function Publish(HeadlineXMLNode) {
if (HeadlineXMLNode.nodeName.toUpperCase() == "BROADCAST") {
content = "";
story = HeadlineXMLNode.firstChild;
while (story != null) {
if (story.nodeName.toUpperCase() == "STORY") {
LEAD = "";
TRACK = "";
URL = "";
ALBUM = "";
URL2 = "";
element = story.firstChild;
while (element != null) {
if (element.nodeName.toUpperCase() == "LEAD") {
lead = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "TRACK") {
TRACK = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "URL") {
url = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "ALBUM") {
album = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "URL2") {
url2 = element.firstChild.nodeValue;
}
element = element.nextSibling;
}
albumString = "";
if(album == "bum"){
albumString = "<img src='cali.jpg'>";
}
else if(album == "album name 2"){

}
else if(album == "album name 3"){

} //and so on
else{
albumString = "<font size='-2'>Album:</font><font color='#336666'> <a href='"+URL2+"'><"+ALBUM+"></a></font>";
}
content += "<body><font size='+2'><b>"+LEAD+"</b></font><br>"+albumString+"<br><font size='-2'>Track: </font><font color='#ff0000'><a href='"+URL+"'>"+track+"</a></font></body>";


txt.htmltext=content;


}
story = story.nextSibling;
}
}
}



we are beginners with flash and have been using a code we found about displaying xml headlines.

Sorry if we have this in the wrong area.

shubs6
01-15-2008, 08:01 AM
Hey buddy, you are showing your XML it in a textarea component and its a bug of textarea component in some versions of Flex (when Flex app is used with AIR) that images don't show. i had faced the same issue and a simple workaround is that you show your content in HTML component rather than textarea. i mean use <mx:HTML> component rather than <mx:Textarea> and then do the same.
Ex - if your HTML component id is txt, then txt.htmltext = content will do the trick.

check this link too
https://bugs.adobe.com/jira/browse/SDK-14238?rc=1

If this doesn't solve the problem do reply back....