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);