- Home
- Tutorials
- Flash
- Intermediate
- 'Cool and Practical' Sound Effects

Page 3 of 15
Importing and Exporting Sound Clips
Flash MX 2004 offers a built-in sound editor, which is fine for simple editing tasks. However, this tool is too basic for most needs: it doesn't allow you to add effects to your sound selections, for example. I definitely advocate the use of a more powerful sound processor, especially when it comes to trimming, duplicating, and looping clips.
You can import a sound clip from the File menu just as you would any other media type. Imported sounds can be applied directly to buttons and button states (Up, Down, Over, etc.), incorporated via streaming external files, included through ActionScripted control in the Action Panel, or added via other means.
The addition of a "click" sound to a button's Down state to simulate a real world mouse click is an example of a basic sound effect. It doesn't requireActionScript knowledge, but it certainly can be created via script. In the following example, the necessary code is applied to a button called myButton, which references a sound clip that has a linkage identifier of mySound in the Library Panel:
myButton.onPress = function ()
{
newSound = new Sound ();
newSound.attachSound ("mySound");
newSound.start ();
}
For more advanced effects, including streaming and abstract playback mechanisms, we need to look under the hood of the ActionScript Sound class to see how we can control sound from within the interface and code conditions. It's an exciting arena in which you can create interesting and dramatic effects quickly, with just a little imagination.
As this book is concentrated on the creation of effects via ActionScript, we won't cover the integration of sound effects into buttons and frames on the timeline. For examples of this, refer to the Flash MX 2004 documentation.
Let's start with an interesting volume control that's linked to an animation.
Dynamic Volume Control
In the following demonstration, we scale the vertical height of a movie clip dynamically, tying the volume of a sound associated with the clip to its height. It's an important example, as it forms the basis for many of the effects you'll create in future.
To edit a completed version of the effect, locate volcontrol.fla in the code archive.
Setting the Scene
- Create a new Flash document that's 500 pixels wide and 400 pixels high. Set the frame rate to 24 fps (Modify > Document?).
- Rename the default layer Actions, and create two new folders in the Library Panel: Movie Clips and Sound.
- Create a new movie clip symbol in the Movie Clips folder with some arbitrary content. The example in the code archive includes a static text area in which the text "sound effect" appears.
- Drag an instance of the movie clip to the stage and name it clipper.
- Select File > Import to Library? and either select reverb.mp3 from the code archive, or import another sound file of your choice. Place it in the Sound folder.
- Select the sound clip from the Library Panel, right-click and select Linkage?. Check the Export for ActionScript checkbox and enter reverb as the identifier.
The file used here is a short, three-second clip of medium quality chosen primarily because it's a small file.
Having added the element we're going to animate and linked the sound clip for ActionScript export, we can now add the control code.
