Thursday 13 October 2011

how to adjust the volume in Sound object

//define somewhere in your class
private var soundPinkPanther:Sound, soundChannelPinkPanther:SoundChannel;

//load the sound
    soundPinkPanther = new Sound(new URLRequest("audio/PinkPanther.mp3"));
//start to play
    soundChannelPinkPanther=soundPinkPanther.play(0,10);   //start immidiatelly

//turn off the volume
    soundChannelPinkPanther.soundTransform=new SoundTransform(0,0);
//turn it on again
    soundChannelPinkPanther.soundTransform=new SoundTransform(1,0);
//turn it on at middle volume
    soundChannelPinkPanther.soundTransform=new SoundTransform(0.5,0);


In this example, in order to adjust volume I am creating a new SoundTransform object and I assign it to soundChannelPinkPanther.soundTransform. There is no other way :( this way I taken from adobe's (complex example).

If you try something like this
soundChannelPinkPanther.soundTransform.Volume=0 
your will take no effect.

This strange way in order to change the volume, doesn't meet the know OOP way. I hope in future Adobe correct this strange things...