var snd:Sound = null;
stage.addEventListener(MouseEvent.MOUSE_DOWN, function(_)
{
if (snd != null)
snd.play();
else
Assets.loadSound("someSound.ogg", function(s) snd = s;);
});
So at the first click/touch, the sound is loaded. And at the second (and onwards) click/touch, the sound is played. This worked on android but still not giving me sound on iOS.
startButton.addEventListener(MouseEvent.MOUSE_DOWN, startGame);
private function startGame(e:MouseEvent):Void
{
var click:Sound = Assets.getSound('assets/sound/click.mp3');
click.play()
}
That’s it. After playing single sound on mouse_down function all other sounds work fine…at least for me. I’m on OpenFL 2.0, I’m not sure if it makes any difference.
You don’t have to decide manually which format to play. All you have to do is keep both formats in the same folder with the same filename. I’m always using Assets.getSound(‘sound.mp3’) and never had any problems.
As far as I know some versions of Firefox and Opera don’t support mp3, while IE, Chrome and Safari all do but I could be wrong.
You do need to have a touch event (as mentioned above by hcwdikk) that triggers the code, usually a start function.
iPhone/Safari is not capable of playing OGG files, so you will need to use either MP3 or M4A (better format). Both formats will work in any web browser. OGG is the better choice overall, but is currently only supported in Chrome and Firefox. M4A is the next best choice.