Hands-On: Flash MX 2004 Working with Sound File
Exercise 17: Using ActionScript Behaviors with Sound Files
Sounds could be important to your Web page, and let’s assume that you
will be adding sound. Now you should learn how to control your sounds with Flash
MX 2004 ActionScript Behaviors.
- Re-load the testSharedSounds.fla file or open a new file and add
a sound file to the Library.
- Open your Library [F11] and select an audio file from what is available.
- Click the Library Option button, and then click Linkage.
- Select Export for ActionScript.

- Enter a distinctive name for the identifier field or use the
default name.
- Leave the other fields at their default values, and then click OK.
Add
a set of buttons to Start and Stop the Music on the Stage. (You may choose to
add the sound to the Timeline instead, if you do, skip the steps outline how
to put a button on the Stage.)
- Add a layer to hold the buttons on the Timeline and rename it buttons.
- Select Window > Other Panels > Common Libraries > Buttons.
- Choose the Playback folder and then select both a Playback - Play and
a Playback - Stop button for the Stage.
Select
the Playbutton object on the Stage or Timeline keyframe if
you have no buttons.

- Click the Window menu, point to Development Panels, and then
click Behaviors.
- Click the Plus sign +, located in the upper-left portion of
the Behaviors panel, point to Sound, and then click Load Sound
from Library.
- Enter the name of the audio file in the Linkage ID field.
- Enter a unique name in the instance field of the Properties panel.
I called mine comfort for the comfortable.wav file I’m using.

Select Play
This Sound When Loaded.
Click OK.
- Note: If the audio file was added to a Timeline frame, the event field will
be disabled.
- Click the Control menu, and then click Test Movie to test
the ActionScript, or use [Control] + [Enter].
- Your button will play the sound file when pressed, however, the Stop button
hasn’t been set up yet, so that is next.
|