If you need to fetch data within Flash which resides on another domain, you will find out it will not work once you test it outside Flash.exe. XML.load(), LoadVars() and sendAndLoad() will return false because of cross-domain security issues.
Where the cross-domain file did not do any good, I found another solution to fetch cross-domain XML data. The so-called 'shim' file.
One important thing: this solution is for the situation when you have control of the server that supplies the (XML) data to the main Flash file on a server out of your control.
The shim file is basically a second movie, hosted on the same server as the data source. The main movie loads the shim movie using loadMovie or the data with loadMovieNum, so both movies are loaded into the Macromedia Flash Player at the same time (on different levels).
To create a shim file just create a new Flash file. In the first frame put the following ActionScript:
var loaded = false;
var varXML = new XML();
varXML.ignoreWhite = true;
varXML.load("http://www.yourdatadomain.com/yourxmlfile.xml");
varXML.onLoad = function(success) { if(success) loaded = true; }
System.security.allowDomain("http://www.yourflashdomain.com/");
Because both documents are in the same domain, the XML request will be processed. The shim file size is only around 250 bytes, so it won't take up much bandwidth.
While loading cross-domain data will trigger security issues, loading a SWF file will not. Hence the next step: load the shim file into your main movie. In your main movie's actionscript add the following:
loadMovieNum("http://www.yourdatadomain.com/shim.swf", 1);
var varXML = new XML();
this.onEnterFrame = function() {
if(_level1.loaded) {
delete this.onEnterFrame;
varXML.parseXML(_level1.varXML);
// Do something with the XML //
}
}
Because you do not know when the data finished loading, I added an onEnterFrame function which keeps checking the status. If the XML data has loaded, parse it into the _root level and go wild with it!
Page Turning Software
desoja.jain<at>gmail.com
Apr 2, 2009 01:05 GMT
#1