Flash XML Caching Solution

MORE TOPS
757 views | 4 replies
flashreseller
Yesterday a customer ask for a solution to this problem. After some research i have found this solution and i think this would help many.

First solution i found is this:

xml.load("xmlFile.xml?"+Math.random());

Essentially, Flash will think that the file is a different URL each time it loads the file and the psuedo parameter (’?+Math.random()&rsquo will be ignored for the file request. Clever and effective.
Posted on Aug 8, 2009 | Reply | Reply with Quote | Send PM | Report
sportswidgets
Thanks man. Was looking for a solution to fix this issue.
Posted on Aug 9, 2009 | Reply | Reply with Quote | Send PM | Report
alex
Thanks FlashReseller for this great fix. Hope that would help all our developers that encounter this problem.
Posted on Aug 9, 2009 | Reply | Reply with Quote | Send PM | Report
OXYLUS
A more effective one would be:

if(_level0._url.indexOf("http://" >=0){
xml.load("xmlFile.xml?"+String((new Date()).getTime()));
} else {
xml.load("xmlFile.xml";
}

This way it will work when ran locally too, in the idea that the query will throw an error if tested locally. Also, with random, even if chances are small, you could get the same number consecutively and therefore load the cached xml. With getTime you can never go wrong, as every time you will get an unique number.
Posted on Aug 18, 2009 | Reply | Reply with Quote | Send PM | Report
flashreseller
Hmmm....
Good idea. I'll test it to see how it works.
Thanks oxylus for this.
Posted on Aug 19, 2009 | Reply | Reply with Quote | Send PM | Report