05-08-2011 08:51 PM
var sound : Sound = new Sound(new URLRequest('MySound.mp3'));
to play it, then i use
Sound.close() to stop playing it, but it doesn't work, is there a problem with it? or is there another way to stop the sound?
05-08-2011 09:15 PM
welcome to the forums! what you need to do is create a SoundChannel variable to control the sound. when you do sound.play() its actually a reference to a SoundChannel object. From there you can stop and play it. Here's an example:
var sound:Sound = new Sound(new URLRequest('MySound.mp3')); var soundChannel:SoundChannel = sound.play(); soundChannel.stop();
hope that clears things up. good luck!
01-19-2014 10:20 AM
btw if the soundchannel is used for other sound, it can not be stopped using the soundchannel.stop() method. Like this:
var sound1:Sound = new Sound(new URLRequest('Gamebg.mp3')); var sound2:Sound = new Sound(new URLRequest ('Sound2.mp3')); var soundChannel:SoundChannel = sound1.play(0,99); //loop the sound indefinately. Useful for game background music. /... var soundChannel:SoundChannel = sound2.play(); soundChannel.stop(); //only stops sound2 //this does not stop the first sound1.
simple workaround would be making seperate soundchannel for background music.