var soundLocation:String = "Musica01.mp3";
var sndFX:Sound = new Sound();
sndFX.load(new URLRequest(soundLocation), sndLoaderContext);
var sndChannel:SoundChannel = new SoundChannel();
var sndLoaderContext:SoundLoaderContext = new SoundLoaderContext(3000);
var isPlaying:Boolean = false;
function playSound(e:MouseEvent):void {
if (!isPlaying) {
sndChannel = sndFX.play();
isPlaying = true;
sndChannel.addEventListener(Event.SOUND_COMPLETE, sndComplete, false, 0, true);
}
}
function stopSound(e:MouseEvent):void {
if (isPlaying) {
sndChannel.stop();
isPlaying = false;
sndChannel.removeEventListener(Event.SOUND_COMPLETE, sndComplete);
}
}
function sndComplete(e:Event):void {
isPlaying = false;
sndChannel.removeEventListener(Event.SOUND_COMPLETE, sndComplete);
}
playBtn.addEventListener(MouseEvent.CLICK, playSound, false, 0, true);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound, false, 0, true);
Muchas gracias a todos.
Saludos.