sfmultimedia.net

sfmultimedia :: actionscript salons :: sound

/

Actionscript Salon #4: The Sound Object

Many, many multimedia projects – Flash-enabled or otherwise – make little to no use of sound. This is a terrible shame, as Flash has remarkable facility with audio. From the management of multiple audio tracks, to the streaming of mp3s, to variations in volume and balance, one can have great fun and infuse great life into Flash projects by making clever, dynamic use of sound.

In Actionscript, the key to all this fun and adventure is the Sound Object. This month at the AS Salon, we’re going to discuss this often-overlooked area of Flash. We’ll introduce basic control of audio through Actionscript, show off a few sound interfaces (both the simple so you can see how it’s done, and the complex to give you something towards which to aspire!). If time permits, we’ll build our very own mp3 player.

Relevance/availability: This salon was created in Flash MX 2004 (Player 7) using Actionscript 1. The concepts largely remain relevant, but note that Flash CS3 allows for more sound channels. I haven't yet delved into sound management in Actionscript 3, so I can't vouch for the relevance of the code in that area.

Presentation slides (swf)

Basic method for attaching an internal sound. An example (seen at the Salon) which demonstrates the basic method of attaching a sound. Four variations are included. Note that the fla is large (966k) because there is an audio track included.

View the swf
Download the fla

Record Player. This example demonstrates all the methods and properties discussed in relation to internal sounds: start(), stop(), setVolume(), setPan(), position and duration. Again, he fla is rather large (995k) because there is an audio track included.

View the swf
Download the fla

Streaming MP3 Player. A simple MP3 player which shows the use of external audio in Flash. We track many properties here: file size, position, and duration. We also look at ID3 tags, which give us the ability to find information about the track, such as artist, song name, genre, and so forth.

This file also shows how to test throughput, which is very useful if you're trying to determine the user's bandwidth and decide whether you want to deliver high or low-quality content.

View the swf
Download the fla