I’ve just been helping someone on IRC who was having a problem with their site. First time they loaded the page the site ran fine, however, the second time their code failed to execute correctly, however on clearing their cache it was all fine again. I’ve run into the problem this guy was having a few times and it’s amazing how common it is.
The problem was with the way they were loading the sound, it seems a fairly common thing for people to first load the sound and then add a listener. While this seems fine there is an issue with some plugin/browser combinations that mean when the file is cached it’s loaded before the onLoad event gets fired. Take the following as a bad example:
var mySound:Sound = new Sound(soundTarget);
mySound.load("mySoundFile.mp3");
mySound.onLoad = soundLoadComplete;
This code snippet will work correctly the first time it is run, however problems will be caused the second time through as the file will load instantly after the mySound.load call, this means the mySound.onLoad event wont be fired as it hasn’t yet been set, to get around this simple ammend the code to the following:
var mySound:Sound = new Sound(soundTarget);
mySound.onLoad = soundLoadComplete;
mySound.load("mySoundFile.mp3");
Hopefully this can be useful for people getting caught in this same trap in future!