Monday, February 9, 2009

Art 351 Audio in Flash

General Sound Notes
0. Wear headphones.
1. Flash accepts .wav and .mp3 directly.
2. Pre-edit your sounds as much as possible in an audio program such as Garage Band or Audacity. Only import the parts you need. Flash is a clunky and inefficient place to edit audio.
3. Flash will recompress your audio file unless you tell it not to. The recompression can make the file sound lousy. Again, you'll have more control doing this in your editing program.
4. Keep all of your sound files together with your .fla files.

Here's how to bring sound into Flash
1. File > Import > Import To Library
2. Right click on the new sound symbol in the Library. Choose Properties.
3. Set your compression choice. Raw will stop Flash from compressing any further. This is usually what I'm after.
4. You'll see a dialogue box (pictured above). Hit the "Advanced" button at the bottom right of the dialogue box.
5. Check Export for ActionScript. Export in first frame will be checked too and an identifier name will also be added. Without this step, your ActionScript won't be able to refer to this file and nothing will work.
6. Many folk recommend 24 khz for music and even 11 khz for spoken words. Lower quality sound = lower bandwidth = faster load times. Mono is often just fine.

Here are the flame.wav and crash.wav files from Andy Harris' Beginning Flash Game Programming For Dummies. It's a great book.
Here's the basic sound.fla file taken from Harris' book.
Here's the Audrey.fla demo we did in class (where Miles accidentally wrote the code on the movie clip instead of the frame). Thanks to Melissa B. for letting us mangle her work!

Here's the code for the basic audio:
// ActionScript 2.0 Basic Sound handling based on Andy Harris' Beginning Flash Game Programming For Dummies. Adopted by Sir Milesicles

// Creates a movie that plays a sound. Yay.

// declare a new sound object named sndFlame using the new and Sound commands.
sndFlame = new Sound();

// fill the new sound object named sndFlame with an instance of the library symbol named "flame.wav"
sndFlame.attachSound("flame.wav");

// start the sndFlame sound object
sndFlame.start();

No comments: