So far my code stops the sound but once it has stopped the sound no longer works. I don’t see any errors reported.
It is as if the event listener no longer listens…
stop();
var soundClip:Sound = new Sound();
var sndChannel:SoundChannel = new SoundChannel();
var soundClipCompleted = false;
var isPlaying = false;
soundClip.load(new URLRequest("tune.mp3"));
soundClip.addEventListener(Event.COMPLETE,onComplete,false,0,true);
function onComplete(evt:Event):void {
sndChannel=soundClip.play();
soundClipCompleted=true;
isPlaying = true;
Action_BtnPlay.gotoAndStop(2);
}
Action_BtnPlay.addEventListener(MouseEvent.MOUSE_UP, playBtn);
function playBtn (evt:MouseEvent):void {
if(isPlaying && soundClipCompleted){
sndChannel.stop();
Action_BtnPlay.gotoAndStop(1);
}else{
sndChannel = soundClip.play();
Action_BtnPlay.gotoAndStop(2);
}
}
You should set isPlaying and soundClipCompleted variable false.