user2789610
user2789610

Reputation: 129

Changing the volume of a simple soundchannel

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

Answers (1)

Bennett Keller
Bennett Keller

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:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d1f.html

Upvotes: 2

Related Questions