Search code examples
actionscript-3actionscriptswfobject

MP3 files are being cached while using swfsound


I'm coding an audio player using swfsound for non html5 compliant browsers. I've three sample files, sound1, sound2 and sound3.

After doing some tests, I've changed sound1, with other file, but surprisingly the original remains cached in the browser. I've deleted the original file, moved to other folder, no way.

The only way to reproduce successfully the new file is to active the "disable cache" feature. I'm looking for a way or method to unload the previous file (if there's one) before loading a new one. The audio player will be playing different mp3 files, and in the way that is working now, it won't succeed.

I would appreciate any help.


Solution

  • This is a very old, very known issue with a very old and pretty well known work around for avoiding caching of individual links in flash. You simply append junk onto the end of the URL with each call. For example:

    myUrlLoader.load(new URLRequest("http://sameOldSite.com/sameOldfile.mp3?" + new Date().toString() ));
    

    That code is untested so it might not be accurate but you get the idea. By appending new Date, you get a unique string of characters every time you create a new Date() or recycle a single date object and keep calling toString() or getTime() or whatever. You can do the same thing with the global timer object too I suppose. This string of extra junk gets discarded because it's seen as a GET variable and is unused.