Flash CS4 ActionScript 3.0 Tutorial
How to Stop Audio with Flash ActionScript
Once you have added audio, there will come a time that you want it to stop. Whenever audio is added, it continues to play until it hits the end of the audio clip or you tell it to stop.
Audio file (mp3) in an external folder.
Button with instance name of stopAudio_btn.
In a new flash document, add two new layers.
Name the top layer Actions, the next layer Audio and the bottom layer Button.
Choose File > Import > Import to Library.
Navigate to your mp3 file and choose Import.
Open the Library (Window > Library).
Select the first keyframe of your Audio layer and drag the mp3 file from the Library to the stage.
Add a Button Symbol to the Button layer and assign it an instance name of stopAudio_btn in the Properties panel.
Option double-click (PC - Alt double-click) frame one of the Actions layer.
Copy/Paste the following code to the ActionScript panel.
Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The audio starts playing. Once you click the button, the audio stops.
Dissecting the Code
The first line of the code at Step Nine adds an event listener to the button. The button is waiting to be clicked. Once the button is clicked, it runs the function called onStop. The function tells the SoundMixer to stop all sounds.
AIF or MP3
This method works with .aif files (Mac) or mp3 files (Mac or PC).