Flash CS4/CS5 and Sound Controls (AS3)

Flash enables you to deliver audio content via external MP3 files. Once you have figured out how to make Play and Stop controls, you can create all kinds of dynamic presentations that load and play multiple MP3 files. Lots of books and sites show you how to build an MP3 music player, but that's not what we need for most journalism packages.

This page provides free access to three downloadable files:

  1. Sound Controls Exercises v.2 (PDF; 257 KB) for Adobe Flash CS4 or CS5 and ActionScript 3.0
  2. Flash starter file: sound_controls_1.fla (48 KB)
  3. Flash starter file: sound_controls_4.fla (56 KB)

The starter files should work fine in either Flash CS4 or CS5.

By using the PDF and the starter files, beginners at using ActionScript can learn how to write code -- as well as how to build sound controls for Flash movies.

Access to the MP3 files is not provided. You can use any MP3 files to complete these exercises. Simply put them into a folder named audio at the same place where the two FLA files are. The filenames need to match those used in the exercises (of course). Note that filenames cannot have any spaces or any punctuation other than an underscore (_), and filenames in ActionScript ARE case-sensitive.

These exercises assume that you already know how to create buttons, button listeners, and simple functions in ActionScript 3.0. No further experience with ActionScript is required.

1) The first of the four exercises requires this Flash starter file: sound_controls_1.fla (48 KB). The second and third exercise build on that one.

You need to upgrade your Flash player (v.9 or later) to view this tutorial.

2) Above is the end result of the second exercise -- Simple Play and Stop buttons. The Pause button is not functional in this example. Try the Play and Stop buttons. The 30-second music clip is an external sound file, in the MP3 format. The SWF you see here loads that MP3 file dynamically. (The SWF file is 4 KB.)

You need to upgrade your Flash player (v.9 or later) to view this tutorial.

3) Above is the end result of the third exercise -- Adding script for a Pause button. The Pause button is functional in this example. Try all three buttons. The 30-second music clip is an external sound file, in the MP3 format. The SWF you see here loads that MP3 file dynamically. (The SWF file is 4 KB.)

The Pause button above does not restart the song. To restart at the paused position, click the Play button again. (This is all in the ActionScript, and it is all explained in detail in the PDF.)

You need to upgrade your Flash player (v.9 or later) to view this tutorial.

4) Above is the end result of the fourth exercise -- Playing more than one audio file. All buttons are functional in this example. The Pause button functions as a toggle in this example. (The SWF file is 24 KB.)

NOTE: If you are using CS5, it is possible that you will have difficulties with dynamic text fields when you open a FLA that was saved in CS4. Adobe changed the way fonts are embedded in CS5. So if you're trying to use an embedded font in CS5 with a FLA that was saved with CS4, you may need to recreate the text field. If you do so, make sure you use the same instance name on the new field!

Embedding fonts in CS4: For a clear explanation of how to embed fonts in CS4 for dynamic text fields, see Embedding Fonts in Flash CS4. This is significantly different from the method used in earlier versions of Flash.

Embedding fonts in CS5: Read Embed fonts for consistent text appearance -- this is what Adobe has to say about it.

The fourth exercise requires this Flash starter file: sound_controls_4.fla (56 KB).

Access to the MP3 files is not provided. See the note about this at the top of this page.

More ActionScript: If you're curious about how to make all three Play buttons use one single function -- the usual solution would be to use a switch statement (see tutorial: Using the Switch Conditional in ActionScript 3.0).

Download this completed Flash file to view the code including a switch statement: sound_controls_5.fla (60 KB).

Education use: This package was created as an example for my journalism students. It is not intended to be used commercially.

Use and re-use: Flash CS4/CS5 and Sound Controls (AS3) by Mindy McAdams is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Creative Commons License

Updated 7 March 2011 | FLA files updated 10 March 2011