Exercise 8: Adding On/Off Sound Buttons to the Dynamic Text Exercise
Continue with the previous exercise or re-open the dreamSpeech.fla file
so you can add a Fixed Text Block to dress up the page and Sound On and Sound
Off buttons that will play a part of Martin Luther King’s 1963 “I
have a Dream” speech. All the files you need are already in the Library.
Click the background layer on the Timeline and insert a new layer
above it, rename this layer to bannerText.
Using the Text Tool create a Static Fixed Text Block that is 670
pixels wide and 64 pixels tall, use the Properties Inspector panel
to adjust the size after you draw the box.
Type the following text using Verdana, 24pt, white, bold and centered.
Type: Working with Dynamic Text and HTML
~ WAV Files and Sound Buttons ~
Click the buttons layer and add a new layer above it, rename it speakers.
In the first
frame of the new speakers layer, open the Library and drag
a soundOn and a soundOff button onto the Stage.
Click the black selection arrow and then [Shift] click on both
sound buttons.
Use the Align panel [Control] + [K] to align
the buttons, make sure the “to Stage” icon is not selected, and select
the second button from the left on top, Align horizontal center.
Click the speakers layer and add a new layer, it should be directly
below the actions layer; rename it to soundActions.
In the Timeline, select the second frame of each layer(use
[Shift] click to select then), and press [F5] to add another frame
to each layer. Your Timeline should look like the one shown here.
In the soundAction layer, select the second frame and press
[F6] to put in a keyframe.
Select the soundOn button and then in the Properties Inspector panel
type dreamspeech in the instance field.
Open the Library panel and locate the sound folder, double-click it open
and then click once on the dream.wav file inside.
Choose the Libraries Option button and choose Linkage to open
the Linkage dialog box, type dream.wav as the Identifier. Place a check
mark in Export for ActionScript and Export in first frame.
Select the Actions layer, click to the right of the ActionScript
and then press [Enter] to add a new line of script. Choose Global Functions > Timeline
Control > gotoAndPlay and then put a 1 inside of the parentheses (1).
This will cause a loop back to frame 1 when pressed.
With
the soundOn button still selected and select the following from the Behaviors
panel. Click Window > Development Panels > Behaviors or [Shift] + [F3].
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 the instance field name you typed in the Properties panel dreamspeech.
Select Play This Sound When Loaded. Click OK.
Test the Movie, you file should begin to play when you press the soundOn
button.
Now you have to make the soundOff button work.
Click the soundOff button on the Stage.
Enter dreamspeech in the instance field name of the Properties panel
just like you did for the soundON button.
Click open the Behaviors panel and then click the Plus sign +, point
to Sound, and then click Stop Sound.
Enter the name of the sound instance in the sound instance field.
Click OK.
Test your movie one more time, this time you can stop the .WAV file
from playing too. Hopefully, your exercise looks like the one below, and that
it works too!
Save your work. In a future exercise you will want to optimize this
file so it can be published for the Web.