Sound in advanced flash

Sound in AS 3.0 _ Sound, SoundChannel

The best way to use sound in a complex project with a big file size is to load the sounds as mp3 files to the main swf only when needed. To load an external sound we use a URLRequest.
var soundFile:URLRequest= new URLRequest ("music1.mp3");

A sound file in AS3.0 not attached to a timeline should be contained in an instance of the Sound class:
var myMusic:Sound = new Sound();

We then load the URL Request into the Sound variable.
myMusic. load(soundFile);

When sound is loaded as an external file we don't define sync modes for it (as when the sound is attached to a keyframe in the timeline). Sound is quite tricky to control, specially to stop once loaded and called to play. To solve that problem we will use a soundChannel, that temporarily with host the Sound. One soundChannel can host all the sound instances in a project (by holding temorarily each one of the). You can also use a number of soundChannels, when you want several sound to play at the same time.
var sndTrack:SoundChannel = new SoundChannel();
sndTrack = myMusic . play();
sndTrack . stop();

A Sound instance can also handle the play of a sound file by itself, but not the stop.
myMusic . play()
;

The Sound.play() method can work with 2 parameters: startTime(in milliseconds) and loops, to have better control of where the sound begins to play, and how many times it should repeat.
sound_instance. play (startTime , loop);
myMusic . play (0, 5);

myMusic . play (1025, 2);

Panning

An individual SoundChannel controls both the Left and Right stereo channels of a sound. If an mp3 is mono, both channels will be identical. The Pan property of a soundChannel object can be used to specify a different volume level for each of the left/right channels during playback. Link to adobe help. The range will go from:
(-1) Left channel plays at full volume and Right channel is silent,
(0) Both channels play balanced with mid volume level, default.
(1) Left channel is silent, Right channel plays at full volume.

To define panning you need to use a soundTransform object.
var snd:Sound = new Sound();
var trans:SoundTransform = new SoundTransform ( 0.6 , -1 );
// SoundTransform ( volumeValue , panValue )
var ch:SoundChannel = snd.play ( 0 , 1, trans) // Sound.play ( startTime , Loops, soundTransform)

You can also set a gobal Volume and global pan values for ll sounds at once by using the soundTransform property of the SoundMixer
SoundMixer . soundTransform = new SoundTransform ( 1 , -1 ) // SoundTransform ( volumeValue , panValue )