开发者

Stop all sounds permanently in AS3

I have a main swf which has sound on/off buttons. It has many SWF's which are loaded into different placeholders at different time. All of them have different sounds in them. In addition to that there is a music loop going on in the background.

Now, this perticular swf lets call it Father will be placed in some swf later on. What I'm trying to do right now is when the sound off button is pressed turn off all the sounds permanently so the child swf's and their sounds stop too.

I have found a way in AS2 :

global = new Sound( ) //no movie clip target path.

and add the following code to your off button.

on(release){
global.setVolume(0); //mutes all sound
}

and for on button

on(release){ global.setVolume(100); //un mutes all sound }

which ofcourse does not work for AS3. So how can I stop all sounds permanently in AS3? Secondly what if I have one sound (my background loop) which I want to keep going on.

Would be a lot of help, been searching for a while now w开发者_JS百科ithout a appropriate answer.


flash.media::SoundMixer.soundTransform does what you did in AS2.

usage:

SoundMixer.soundTransform = new SoundTransform(0);

note however, this does not stop playback, it only mutes all sounds.


import flash.media.SoundMixer;
import flash.media.SoundTransform;

// volume limits are 0 to 1 (0.1,0.2,0.3,...,1)
SoundMixer.soundTransform = new SoundTransform(0);

This should work :)


If you are using AS3, you should be using Sound(), SoundChannel() and SoundTransform() like so:

urlReq = new URLRequest("location of audio file");
audio = new Sound(urlReq);
soundChannel = audio.play();

You can then call childswfs soundChannel.stop() method.

That should stop all the audio.

Secondly assign different sounds to separate soundChannels, that way you can mute one and keep another(s) going.

Hope that helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜