I've got an issue with my main menu Sound Channel. I need to mute it when the user clicks the difficulty button and advances to the "play" screen, but it keeps coming up as null, even though I can hear the music playing. I'd appreciate any input into the problem, because I've been trying to fix this bug for several days. I know how hard it is to work with only pieces of the puzzle, so I'll try and give you every piece of information relevant to the problem.
Here's the system I've got going:
1) The showMenuScreen() function gets called in the constructor of my document class ("DocumentClass").
2) SoundObject is a class I created to handle the various sound functions. I then call an instance of SoundObject, "soundObject". playSound is a SoundObject function that takes in a string as its parameter.
Here's the code that is called:
soundObject.playSound("menu music");
3) Here's the relevant code from the playSound function:
else if(string == "menu music" && isMuted == false)
{
mmSoundChannel = menuMusic.play();
mmSoundChannel.addEventListener( Event.SOUND_COMPLETE, onMenuMusicFinished );
}
4) When the user clicks a difficulty, this code from the MenuScreen class executes:
public function startGame()
{
if(DocumentClass.main.alwaysUseMouse == false)
{
dispatchEvent( new NavigationEvent( NavigationEvent.START_KEYBOARD ) );
}
else
{
dispatchEvent( new NavigationEvent( NavigationEvent.START ) );
}
soundObject.mute("all menu sounds");
}
5) An event listener from DocumentClass catches whichever one of those two NavigationEvents is dispatched from the last step and calls either a mouse or keyboard function:
public function onRequestKeyboardStart( navigationEvent:NavigationEvent ):void
{
alwaysUseMouse = false;
playScreen = new AvoiderGame(false);
playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath, false, 0, true );
playScreen.x = 0;
playScreen.y = 0;
soundObject.playSound("main song");
addChild( playScreen );
removeChild(menuScreen);
menuScreen = null;
stage.focus = playScreen;
}
Result: The menu song doesn't stop, the play song starts, and more curses are uttered.
I believe that mmSoundChannel is the perpetrator here. Can anyone help me find out why the music keeps playing if the channel is set to null?