flash & caching

Anybody thats done any development work in Flash knows how frustrating caching can be. With the introduction of external XML data this frustration only grows. So here's a technique that I use quite often to workaround this native behavior without creating a thousand incremental file names.

Using PHP, Javascript or the like, simply add a random number to the url string where you call your swf. Here's a couple examples..

PHP
fla/secParent.swf?noCache=<?php echo rand(0, 10000); ?>


Javascript
var randomnumber=Math.floor(Math.random()*11);
fla/secParent.swf?noCache="+randomnumber;


Actionscript
"secParent.xml?noCache=" + Math.floor(random(1000000) / random(1000)));