Using sound in Flash with ActionScript
An external sound file must be in mp3 format
To play sound in anything but the standard way requires a number of steps:
- import the sound
- link the sound, and set it to export with the movie
- Once a sound has been imported to the library, right-click to select linkage and set it to export with the movie
- write the code to attach the sound and play it. This could be in a frame on the timeline or in the release event of a button.
- newSound = new Sound();
- then the properties can be adjusted for: volume, repeating, panning, balance and transformations
To change how a sound starts or plays:
- newSound.start(500); will start the sound a half second after the beginning (1000 milliseconds = 1 second)
- newSound.start(0,2); will start the sound at the beginning and loop it 2 times.
- newSound.stop(); will stop all sounds running
- newSound.stop("filename.ext"): will stop that sound.
- newSound.setVolume(80); adjusts the volume from 0 to 100
- newSound.pan(-100) ; allows you to pan to the far left, with 0 in the middle and 100 at the right