I have a flash file that uses actionscript to read a remote XML file. Thanks to kirupa.com for the tutorial that allowed me to accomplish this. Everything is working pefectly except one little issue.
When the movie loops it requests the XML file again. How can I have it request the XML file only the first time and just re-utilize the data?
that works perfectly! thank you very much. another side problem though. down in the status bar of the browser it always says “transferring data from <hostname>”
do i need to terminate the connection or something so that it will stop doing that?
function movieName ()
{
var url = new String (this._url);
var p1 = url.lastIndexOf ("/") + 1;
var p2 = url.length;
return url.slice (p1, p2);
}
// SET VARIABLES
name = movieName();
var url = 'http://www.example.com/file.xml';
xmlData = new XML();
xmlData.ignoreWhite = true;
//callback function for xml load usually goes here right after constructor
xmlData.onLoad=function(success){
if(success)
{ _root.c_rank = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.h_rank = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
} else {
return false;
}
}
}
if(!xmlLoaded){
xmlLoaded=true;
xmlData.load(url);
}
your problem may be that you’re declaring a callback ‘.onLoad’ function before you create the object it’s associated with. Also you had
xmlData.onLoad = loadXML;
which should probably be:
xmlData.onLoad = loadXML();
(you forgot the parenthesis in there. You don’t need a seperate function like that though. I put everything into the .onLoad handler for you.
i copied and paste what you have above and it works just fine - but i still have the same problem with the flash file “looking” like it is continuously requesting data on the browser status bar. i am not calling an xml file directly, i am actually calling a php file that outputs in xml format - would that cause a problem?
all the rest of the code is exactly the same except the line where the url var gets set - which is below.
var url = 'http://www.example.com/xml.php?item=' + name;
i am pretty solid with the PHP and don’t believe there are any problems there - are there any specific guidelines to using PHP with actionscript that i should know about?