Reputation: 129
I would like to change the volume of a soundchannel, instead of turning it off/ starting it from the beginning.
Here is a bit of my code dealing with the soundchannel, musicIcon
toggles the sound.
function musicToggle(e:TouchEvent){
if(musicIcon.alpha != 1){
Chn_musicLoop = musicLoop.play(0,int.MAX_VALUE);
//Instead of restarting the music, I would like to set the volume to it's max (1)
musicIcon.alpha *= 2;
}
else{
musicIcon.alpha *= .5;
Chn_musicLoop.stop();
//Instead of stopping the music, I would like to set the volume to 0.
}}
What code would I need to do this?
Upvotes: 0
Views: 354
Reputation: 1714
I believe you are looking for SoundTransform
class.
Basically:
var st:SoundTransform = new SoundTransform(0.5, 0);
Chn_musicLoop.soundTransform = st;
The SoundTransform
parameter of 0.5
would put your "volume" at halfway. The parameter is a range from 0 to 1.
Here's a reference in AS3 from adobe:
Upvotes: 2