downloads - lesson 8

Click SWF to play the example. Right-click (or Control-click/Mac) FLA to download the file and see the Timeline, etc.

Note: If you get a Missing Font Warning when you open the FLA in Flash, it's okay. Click the Use Default button.

All music files used here are freeware downloaded from Flashkit.com. Please note that any FLA using the attachSound() method will be a fairly large file, because the uncompressed audio is in the FLA.

If you download a FLA file that uses "loadSound," you must also download the MP3 file(s).

BONUS > Simple Sound
Very basic buttons introduce the concepts of controlling sound with ActionScript. Uses the loadSound() method, so you'll need this MP3 if you download it.
SWF (9 KB) :: FLA (76 KB)

> attachSound (01)
This exercise (8.1) shows how to import a sound file and use ActionScript (and Linkage) to play it, looping 5 times, with code on Frame 1. This is a one-frame movie.
SWF (28 KB) :: FLA (857 KB)

> attachSound (01a)
This example demonstrates that the sound will not stop just because you wrote a stop() action on the last frame in your Timeline. This movie is 45 frames (3 seconds) long.
SWF (29 KB) :: FLA (858 KB)

> attachSound (01b)
This example takes the previous one and stops the sound with its own stop() action on the last frame of the Timeline. This movie is also 45 frames (3 seconds) long.
SWF (30 KB) :: FLA (859 KB)

> attachSound / Stop and Play buttons (02)
This example is a lot like attachSound (01) -- except now two buttons have been added to stop and restart the sound. All the code is on Frame 1. This is a one-frame movie.
SWF (29 KB) :: FLA (861 KB)

> loadSound (03)
This exercise (8.2) shows how to load an MP3 file that is outside the SWF. All the code is on Frame 1. This is a one-frame movie.
SWF (5 KB) :: FLA (24 KB) :: MP3s

> loadSound / Stop and Play buttons (04)
This example is a lot like loadSound (03) -- except two buttons have been added to stop and reload the sound. All the code is on Frame 1. This is a one-frame movie.
SWF (6 KB) :: FLA (33 KB) :: MP3s

> loadSound / stopAllSounds (04x)
In this example, you can dynamically load any one of four external MP3 files. Note that if you play the SWF online, there may be a delay the first time, for each of the audio files. Most of the code is on the buttons. This is a one-frame movie.
SWF (6 KB) :: FLA (32 KB) :: MP3s

> loadSound / onSoundComplete (05)
In this exercise (8.3), you learn how to use ActionScript to make something happen when a dynamically loaded MP3 file comes to its end.
SWF (6 KB) :: FLA (26 KB) :: MP3s

> loadSound x 2 / two external MP3 files (06)
In this exercise (8.4), the script causes two dynamically loaded MP3 files to play at (roughly) the same time. This is a one-frame movie.
SWF (6 KB) :: FLA (27 KB) :: MP3s

> loadSound 1 + 1 / onSoundComplete (07)
This example is very similar to the previous one (06), but here the script causes a second dynamically loaded MP3 file to play after the first one has concluded. This is a one-frame movie.
SWF (6 KB) :: FLA (27 KB) :: MP3s

> attachSound / Pause button (08)
In this exercise (8.5), a Pause button is scripted to read the position of the attached Sound object and store it when the music stops. Press the Pause button again, and the stored value is used to restart the sound at the same place. Note that if you play the SWF online, there may be a delay.
SWF (186 KB) :: FLA (2.1 MB)

> loadSound / Pause button (08a)
The only difference between this SWF and the previous one is the sound file: This one is an MP3 outside the SWF. The difference is reflected in the script on Frame 1. The script on the Pause button and the Replay button is exactly the same as in the previous file (08).
SWF (8 KB) :: FLA (37 KB) :: MP3s

> attachSound / Mute button (09)
In this exercise (8.6), a Mute button is scripted to toggle the volume on and off, but not to stop the sound file from playing. The example illustrates how this allows the sound and images to stay (roughly) in sync.
SWF (47 KB) :: FLA (470 KB)

> loadSound / Mute button (10)
In this version, the Mute button is exactly like the previous one (10). Because the sound is loaded, however, there is a small load-checking script added to Frame 1, so that the pictures do not get ahead of the soundtrack. The sound file is loaded on the Play button here.
SWF (9 KB) :: FLA (46 KB) MP3s

> attachSound / Pause button for whole show (11)
In this version, the Pause button makes both the slides and the sound stop the first time you click it. Click it again, and the movie resumes from the same position.
SWF (47 KB) :: FLA (485 KB)

> loadSound / Pause button for whole show (12)
This version works like the previous one (11), but with a dynamically loaded MP3 file instead of an attached sound. As in example (10), a small load-checking script was added to Frame 1, so that the pictures do not get ahead of the soundtrack. The sound file is loaded on the Play button here.
SWF (9 KB) :: FLA (34 KB) :: MP3s

> attachSound / music fades out (13) BONUS
This movie uses the sound loop from (01) as the soundtrack for a little slideshow. On the final frame, the music fades out gracefully, thanks to a script using getVolume() and setVolume().
SWF (31 KB) :: FLA (899 KB)

> loadSound / timing with audio (14) BONUS
This movie brings together many of the parts of this lesson. It demonstrates how to synchronize changing images directly to an externally loaded MP3 file as it plays. This is done with ActionScript, of course. This is the best of all the "faces" examples on this page, because the MP3 (loaded) has the best quality, and the audio will not get out of sync with the image sequence.
SWF (9 KB) :: FLA (45 KB) MP3s

Download all FLA files for this lesson (requires Flash MX or later); note that the MP3 files are NOT included:
> Windows (.zip) 5.6 MB
> Mac (.sit) 5.6 MB