Skip to main content
Inspiring
October 9, 2009
Question

AS3 stopping audio streaming inside a layer

  • October 9, 2009
  • 1 reply
  • 1293 views

Sometimes I get ahead of myself and have to stop and say how the hell did I do this before? I'm referring to a simple stop button I need to put in a flash animation. I know how to code calling a sound from the library, starting and stopping. But how do I stop audio that is streaming inside a layer from a button ?

var my_sound:Sound = new Sound();
my_sound.load(new URLRequest("yoursoundfile.mp3"));
var my_channel:SoundChannel = new SoundChannel();

//2.
play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);

//3.
function playSound(event:MouseEvent):void{
my_channel = my_sound.play();
}

//4.
function stopSound(event:MouseEvent):void{
my_channel.stop();
}
This topic has been closed for replies.

1 reply

Inspiring
October 9, 2009

If I' m understand right you have a button with timeline and have sound on layer. If it is right I'm not sure that you can stop this sound. All you can do is to use soundTransform property and set the volume to 0. Or you can make a keyframe without sound and jump to it

mentlityAuthor
Inspiring
October 9, 2009

OK what I actually need is a mute and play button for the audio track

So how can I stop, or in this case mute the audio without stopping the animation, follow?

example, volume is at 100

click button volume goes to 0

click same button or another button volume goes back to 100

???

Inspiring
October 9, 2009

Use someting like this in event listener of th button

var transform:SoundTransform = new SoundTransform(0);

mcClip.soundTransform = transform

wher mcClip is the clip wich have sound setted to layer . If the button is inside of the clip mcClip is 'this'.