Hi everyone
i wrote this code that plays music on the background
but it’s keeps playing also on the next frame i dont want it to play it
what can i do?
thank you
var req:URLRequest = new URLRequest(“song.mp3”);
var isPlaying:Boolean = true;
var snd:Sound = new Sound(req);
var channel:SoundChannel;
var pausePosition:Number = 0;
channel = snd.play(pausePosition);
playBtn2.buttonMode = true;
playBtn2.gotoAndStop(2);
playBtn2.addEventListener(MouseEvent.CLICK, playPause);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event) {
pausePosition = 0;
channel = snd.play(pausePosition);
isPlaying = true;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
function playPause(event:MouseEvent):void {
if (isPlaying == false) {
channel = snd.play(pausePosition);
isPlaying = true;
playBtn2.gotoAndStop(2);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
} else {
pausePosition = channel.position;
channel.stop(); // Stop Playing
playBtn2.gotoAndStop(1);
isPlaying = false;
}
}