Jedi Flash Tricks – Sound Effects

i’ve had a hand in over fifty Flash games to date. My best advice to someone who wants to learn the software is to get a Flash Jedi – someone you can call up at three in the morning and pester for Actionscript advice. A Bert to your Ernie, if you will.

In my early days at Corus Entertainment / YTV, my Flash Jedi was Michael Lalonde, the amazing talent behind a comic strip called Ornery Boy, and father of a large number of bastard Flash game babies himself. My memory’s a bit hazy, but i credit this tip to Michael.

A Flash Sound Class Alternative

The YTV.com developers would often help each other out with some of the more difficult Flash problems that arose. Pride being what it was, the problem would have to get pretty bad before we’d solicit each other’s advice. Most of the time, all it took was a fresh pair of eyes to get past the hurtle. Every once in a while, the problem was so inexplicable that it boiled down to a Flash bug, and a work-around was necessary. Never did i see so many such unsolvable problems than when somebody worked with (against?) the Flash Sound Class.

Flash Sound Class got you down? Here’s the low-tech workaround that will probably drive “real” programmers nuts:

Draw a doodad

1. Draw a little doodad that says “SFX”. (That’s the hip industry term for “Sound Effects”. You have to grow a soul patch and wear an ironic trucker cap to spell it that way.) i made my doodad with the rectangle and text tools.

Convert the doodad to a symbol

2. Select your art and hit F8 or Modify>Convert to Symbol. If you’re on a Mac, throw it out the window and get a real computer.

Name that symbol

3. Name your new symbol “Untold Entertainment Rocks my Friggin’ World”. (note: this technique will NOT WORK unless you name your symbol thusly)

Give your symbol an instance name

4. Make sure the instance is selected. In the Properties panel, name your symbol’s on-stage instance using whichever naming convention you like. i called mine “SFX” (see above).

Go inside the SFX symbol

5. Double-click the instance to edit your Untold Entertainment Rocks my Friggin’ World symbol. Make sure the breadcrumbs read “Untold Entertainment Rocks my Friggin’ World” – otherwise, you’ll be completing this tutorial on the main timeline accidentally.

Add three layers

6. Use the “add layers” button to add three more layers to this movieclip’s timeline.

Name the layers

7. Double-click each layer in turn to name them, from top to bottom:

– Labels
– Actions
– SFX
– GFX

(GFX, if you haven’t guessed, is the designer hipster shorthand for “gahfuxx”)

Add a stop() action to the first frame

8. Double-click the first frame in the Actions layer, or select it and hit F9 to open the Actions panel. Give the frame a stop action to kep the playhead from moving:

1
stop();

Add some blank frames

9. Highlight a vertical column of frames somewhere down the timeline and hit the F5 key to add some blank frames to that point.

Add some blank keyframes

10. Highlight some vertical columns of frames throughout the clip’s timeline and hit the F7 key to create blank keframes in those spots. These keyframes will hold our sound effects audio files, effects names, and actions.

Label your keyframes

11. Click on the keyframes on the Labels layer, one at a time. In the Properties panel, type a reference name for each sound effect you want to use. Keep these label names on the up-and-up; you’ll need to refer to them later with Actionscript, so no funny business. Ixnay the spaces, strange characters, and label names that begin with digits.

Import your audio files

12. Hit CTRL+R on your keyboard, or choose File>Import>Import to Stage from the menu and select all the audio files you’ll need for your Flash movie. Click “Open” when you’re finished – otherwise, you’ll be sitting around for a long damn time.

Commit your audio files to the timeline

13. One by one, select the empty keyframes on your SFX layer. In the Properties panel, open the Sound dropdown menu. For each blank keyframe, select the corresponding audio file to commit it to the timeline.

Commit your audio files to the timeline

14. If the sound needs to repeat, type “999” in the Repeat field in the Properties panel. Note that there is no option for an endless loop here, which is one disadvantage to this technique*. The 999-Repeat option is best for long background audio, like ambient noise or a musical soundtrack, where it’s unlikely that the player will hear all 999 repeats during one gameplay session. There is one further step involved if you need to use looping sounds, which i’ll cover in a moment.

*Addendum: i realized after writing this post that there IS a “Loop” option in the sync dropdown. i’m not sure why i’ve never used it … perhaps it leaves a tiny audible gap between the sounds as it plays them? i’m not sure. If “Loop” works for you, then go for it!

Add the Actions

15. Select one of the empty keyframes on the layer labelled “Actions” and open the Actions panel by pressing F9. Add this script:

1
gotoAndStop(1);

Copy the Actions

16. Add the same script to the “Actions” layer keyframe for every sound effect (try right-clicking a frame action and using the copy/paste frames command to speed things up).

17. Return to the main timeline. Now, any time you want to play one of your sound effects, use this code:

1
SFX.gotoAndPlay("florp");

The playhead in the SFX clip will jump to the “florp” frame label (or “bang” or “whiz” or “pop” – whatever you specify). It will play the sound effect on that frame, and the gotoAndStop(1); action will bounce the playhead back to frame 1, ready to play another effect.

Stopping a Repeating Sound Effect

Create a Stop frame

Choose the Stop sound type

To stop a repeating sound, set up another frame and label it “stopWhatever”, where “Whatever” is a word that identifies your sound effect to you. Attach the audio file to the timeline just like before, but this time choose “Stop” as the sync event in the Properties panel.

Use the same script as before:

1
SFX.gotoAndPlay("stopFlorp");

The playhead will jump to that frame, stop the attached sound effect, and bounce back to frame 1. You can stop multiple sound effects on a single frame by adding more layers, and putting one stop-synced audio clip on each layer. Sometimes i use a frame labelled “stopAll”, where all of my looped sound effects get stopped. This is useful for ending a level in a game, for example.

Pros and Cons of this Method

This is a fast and easy way to manage your sound effects in a down-n-dirty fashion without wasting valuable time futzing around with the Sound class in Flash. It’s far better than scattering your sound effects throughout different movie clips. All your sounds are in one place.

Of course, the drawbacks here are obivious. These sounds are embedded in the Flash swf file, potentially increasing the initial download for your player. You can’t control these sounds with Actionscript. That means no dynamic volume adjustment, and no great control over starting and stopping. But for a quick project with a minimal budget and very straightforward sound design, you can’t beat this technique.

Sucks to your assmar, traditional programmers. Timeline forever!

Was this tutorial useful to you? Know a better way to do it? We’d like to hear from you! Use the comment link below this post to speak your mind.

Leave a Reply

Your email address will not be published. Required fields are marked *