The flash example on the right will take a moment to load on a slow connection. It demonstrates the Sound object in Flash.
Those who subscribe to this site can download the FLA file here in a zip archive. The FLA file has two layers. The bottom layer contains a fader and a knob from the Knobs and Faders folder found within the common library of buttons (WINDOW-->Common Libraries-->Buttons.fla). The fader is named fader1 and the knob is called knob1.
The library of the FLA file contains an MP3 file of a Bach invention. In the library, click on the object called INV4.mp3 and choose Linkage from the dropdown menu at the top of the library palette. Notice that the file is exported for ActionScript with the identifier name of "bach."

The first frame of the movie has a script associated it that creates the Sound object. The Sound object is attached to a movie clip called blankMC which is a small movie clip that is located offstage in the FLA file. Then the sound with the identifier "bach" is attached to the new sound object. The next two lines set up variables for volume and pan control. The setVolume() and setPan methods of the sound object are then called to set the volume and pan of the mySound1 object to the values stored in the variables vol1 and pan1. Next a variable, "playing", is created to store the current state of playback (true or false). Then there are two functions for starting and stopping the playback of the sound. The playMusic() function only starts playback of the sound if the sound is not currently playing (expressed as !playing). Playback starts at the beginning and loops 10 times as expressed in mySound1.start(0,10).
var mySound1 = new Sound(blankMC);
mySound1.attachSound("bach");
var vol1 = 50;
var pan1 = 0;
mySound1.setVolume(vol1);
mySound1.setPan(pan1);
var playing = false;
function playMusic(){
if (!playing){
mySound1.start(0,10);
playing = true;
}
}
function stopMusic(){
mySound1.stop();
playing = false;
}
Code Listing from frame 1 of the basicsound.fla file
The blankMC movie clip also has a script attached. This script references the vol1 and pan1 variables created in frame 1 of the main timeline (referred to as _root). It sets the value of the vol1 variable to the difference between the current position of the fader1 object and its initial position. It sets the value of pan1 to the value of the variable "level" that is built into the knob1 object on the _root.
onClipEvent (enterFrame) {
_root.vol1 = parseInt(50-(_root.fader1.vertFader._y-_root.fader1.vertFader.inity));
_root.pan1 = _root.knob1.level;
_root.mySound1.setVolume(_root.vol1);
_root.mySound1.setPan(_root.pan1);
}
Code Listing from the blankMC movie clip
The scripts of the buttons for playback are very simple. The play button calls the playMusic() function. The stop button calls the stopMusic() function.
Finally, there is a small dynamic text field that is set to display the current value of the vol1 variable as seen in the properties palette.

That's a quick summary of the sound object and how you can manipulate it using faders and knobs. You can have up to 8 sound objects playing at any one time in a Flash movie. That means you can create multi-track mixers and other interactive sound environments.
Close this window when finished.