'Overlapping sound in as3

Okay, so I am making a game, and I can't figure out how to keep the sound track from overlapping. When the game comes to a lose or win screen, I will click "Play again" and the sound will overlap. I have the sound on it's own layer. Here's what I have so far.

var snd_SolidState = new SolidState();
snd_SolidState.play(0,1);

And on Layer 2 Frame 2 and 3, I have:

snd_SolidState.stop();
snd_SolidState = null;

It says "stop" is not a function. So how would I get the song to stop on the lose/win screens? SolidState is the song.

If the code is related to the click of the "Play again" Button, here is the code for those.

mc_again.addEventListener(MouseEvent.MOUSE_UP,upAgain);
function upAgain(e:MouseEvent){
gotoAndStop(1);
}

Can anyone help?



Solution 1:[1]

The variable snd_SolidState is a Sound object, Sound doesn't have a stop method implemented; The Sound.play() however, returns a SoundChannel object which does...

So you can store that (the SoundChannel object returned by snd_SolidState.play()), which you can later use to stop the song.

PS: I recommend you start typing your variables (ie: var snd_SolidState:Sound;), that way you force yourself to know which object type you're dealing with and can find reference for it; in this case Sound.play().

Solution 2:[2]

You need to use a SoundChannel to stop your music.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Dharman