I'm having problems pausing and restarting a background sound loop. My existing code works fine for everything else but not for this.
Code:
soundOn = true;
function playSound(name) {
if (soundOn) {
_root.soundFX.gotoAndPlay(name);
}
}
keyListener = new Object();
keyListener.onKeyDown = function() {
keyValue = Key.getCode();
keyPressed = Key.getAscii();
//or isDown detection
if (Key.isDown(77)) {
soundOn = soundOn ? false : true;
mute.gotoAndPlay("nosound");
}
}
Key.addListener(this.keyListener);
The above doesn't stop the background loop. If I change part of it to this, it stops it, but doesn't restart it:
Code:
keyListener = new Object();
keyListener.onKeyDown = function() {
keyValue = Key.getCode();
keyPressed = Key.getAscii();
//or isDown detection
if (Key.isDown(77)) {
soundOn = soundOn ? false : true;
mute.gotoAndPlay("nosound");
if(!soundOn){
stopAllSounds();
}
}
}
Key.addListener(this.keyListener);
If I change it to this, it stops the loop, but doesn't always restart it:
Code:
keyListener = new Object();
keyListener.onKeyDown = function() {
keyValue = Key.getCode();
keyPressed = Key.getAscii();
//or isDown detection
if (Key.isDown(77)) {
soundOn = soundOn ? false : true;
mute.gotoAndPlay("nosound");
if(!soundOn){
stopAllSounds();
}else if(soundOn){
playSound("background");
}
}
}
Key.addListener(this.keyListener);
Can anyone help me please?