General Discussion - How to Set Volume in Flash kasselbiddy - Mon Sep 03, 2012 6:47 pm Post subject: How to Set Volume in Flash
Here is how you go about setting the volume of sound in Flash. There are two ways of setting volume, either on a per-channel basis or globally across all channels. Besides, here is a tutorial about how to convert SWF to MOV on Mac with a Mac SWF to MOV converter.
Before we dive in it is worth taking a quick look at the four main classes used when manipulating sound in Actionscript 3.0.
* Sound
An object representing an individual sound. This may be a sound effect or music loop.
* SoundChannel
A channel which plays a single Sound object.
* SoundTransform
Class used to manipulate the volume and/or panning of a sound.
* SoundMixer
A class containing static methods for controlling the global output of sound in a SWF.
Setting the volume of an individual sound
We can set the volume of a single sound channel at two distinct occasions, when the SoundChannel is instantiated as a result of calling the play method of a Sound instance, or we can alter the volume of an already existing SoundChannel.
Volume is set via an instance of the SoundTransform class. A SoundTransform instance is simply applied to the soundTransform property of a SoundChannel. Here we apply a SoundTransform instance with a volume of 0.5 to an existing SoundChannel called myMusicSoundChannel.
myMusicSoundChannel.soundTransform = new SoundTransform(0.5);
Note the volume value is specified as a number between 0 (silent) and 1 (full volume).
Next we set the volume of a SoundChannel during it’s initialization. The Sound instance, mySound, is set to play a single time with a volume of 0.5.
var mySoundChannel:SoundChannel = mySound.play( 0, 0, new SoundTransform(0.5) );
Setting volume globally
Setting the global volume of sound in your SWF is very similar to setting the volume of a single sound. The main difference is that we aren’t manipulating a single SoundChannel instance, rather we use the SoundMixer class.