The following procedures show how to create sound controls similar to the ones shown in the
figure.
To attach a sound to a Timeline:
Select File > Import to import a sound.
1.
Select the sound in the library, right-click (Windows) or Control-click (Macintosh), and
2.
select Linkage.
Select Export for ActionScript and Export in First Frame; then give it the identifier
3.
a_thousand_ways
Add a button to the Stage and name it
4.
Add a button to the Stage and name it
5.
Select Frame 1 in the main Timeline, and select Window > Development Panels > Actions. Add
6.
the following code to the Actions panel:
var song:Sound = new Sound();
song.attachSound("a_thousand_ways");
play_btn.onRelease = function() {
song.start();
};
stop_btn.onRelease = function() {
song.stop();
};
This code first stops the speaker movie clip. It then creates a new Sound object (
attaches the sound whose linkage identifier is
handlers associated with the
using the
Sound.start()
sound.
Select Control > Test Movie to hear the sound.
7.
To create a sliding volume control:
Drag a button to the Stage, and enter
1.
Select the button, and select Modify > Convert to Symbol. Be careful to select the movie
2.
clip behavior.
This creates a movie clip with the button on its first frame.
Select the movie clip, and enter
3.
Select Frame 1 of the main Timeline, and select Window > Development Panels > Actions.
4.
Enter the following code into the Actions panel:
5.
slider_mc.top = slider_mc._y;
slider_mc.bottom = slider_mc._y;
slider_mc.left = slider_mc._x;
slider_mc.right = slider_mc._x+100;
slider_mc._x += 100;
190
Chapter 6: Creating Interaction with ActionScript
.
play_btn
stop_btn
playButton
and
Sound.stop()
knob_btn
slider_mc
.
.
a_thousand_ways
and
objects start and stop the sound
stopButton
methods, and also play and stop the attached
as the instance name in the Property inspector.
as the instance name in the Property inspector.
) and
song
. The
event
onRelease
Need help?
Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?
Questions and answers