user3102529
user3102529

Reputation: 63

How can I set a specific sound effects to a specific volume?

I have a variable set

var vol = 0.25;

this var changes on demand and works fine.

In my flash game I have some sound effects on movieclips that sound only when the movie clips are being played.

I would like to set all of my sound effects to the same volume in one as3 file.

Although I have my sounds playing in my timeline on as3, is there a way to get all of my sounds together on one as3 file in order to set them all to a specific volume.

I was thinking about something like this:

var isSoundOn = true;
if (isSoundOn == true) {

    // get all sounds that i would like to change volume on
    // if in game play and any of the sound effects are ready - play all these sounds with my specific volume setting.

}

my code looks a bit like this but doesn't work

In FlashDevelop... My main Class...

public class Platformer extends GameLoop
{
public var redMonster:RedMonsterFla;
public var SoundFxVol:Number;


public function Platformer( )
{



}

    // here i have functions that open a popUp
    // inside the popUp i can change variable "SoundFxVol" with my volume slider  


    // here i would like to set my volume to some of my movieClips with soundFx

public function set VolumeForSoundEffects(value:Number):void
{
    // set array of movieClipsThatContainSound


    var movieClipsThatContainSound:Array = new Array( redMonster );

    var st:SoundTransform = new SoundTransform(value);

    SoundFxVol = value;

    for each( var mc:MovieClip in movieClipsThatContainSound  ) mc.soundTransform = st;
}

public function get VolumeForSoundEffects():Number
{
    return SoundFxVol;
}

}

I flash I have a movieClip called RedMonster with a library linkage to as3 as RedMonsterFla; On redMonster MovieClip I have lots of labels, one of them is jump - this has a sound. There is no code on the redMonster timeline.

Upvotes: 0

Views: 522

Answers (1)

Vesper
Vesper

Reputation: 18747

You can use your movie clips' soundTransform property to adjust volume of those sounds that are played within it. But, you cannot set a var and get all dependant SoundTransform objects to adjust themselves, so write a setter property function.

private var vol:Number=1.0;
public function set volume(value:Number):void {
    var st:SoundTransform=new SoundTransform(value);
    vol=value;
    for each (var mc:MovieClip in whateverArray) mc.soundTransform=st;
}
public function get volume():Number { return vol; }

whateverArray is supposed to be the array that holds all the movie clip instances that are dependant on setting volume here.

Upvotes: 1

Related Questions