![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
You use the built-in Sound class to control sounds in a SWF file. To use the methods of the Sound class, you must first create a Sound object. Then you can use the attachSound()
method to insert a sound from the library into a SWF file while the SWF file is running.
To see an animated demonstration of sound controls, click the Play button and adjust the volume and pan.
The Sound class's setVolume()
method controls the volume, and the setPan()
method adjusts the left and right balance of a sound.
The following procedures show how to create sound controls like the ones shown above.
a_thousand_ways
.playButton
. stopButton
. speaker
.speaker.stop(); song = new Sound(); song.onSoundComplete = function() { speaker.stop(); }; song.attachSound("a_thousand_ways"); playButton.onRelease = function() { song.start(); speaker.play(); }; stopButton.onRelease = function () { song.stop(); speaker.stop(); }
This code first stops the speaker movie clip. It then creates a new Sound object (song
) and attaches the sound whose linkage identifier is a_thousand_ways
. Next, it defines an onSoundComplete
handler for the song object, which stops the speaker
movie clip once the sound has finished. Lastly, onRelease
handlers associated with the playButton
and stopButton
objects start and stop the sound using the Sound.start()
and Sound.stop()
methods, and also play and stop the speaker
movie clip.
This creates a movie clip with the button on its first frame.
on (press) { startDrag(this, false, left, top, right, bottom); } on (release) { stopDrag(); }
The startDrag()
parameters left
, top
, right
, and bottom
are variables set in a clip action.
onClipEvent (load) { top = _y; bottom = _y; left = _x; right = _x+100; _x += 100; } onClipEvent (enterFrame) { _parent.song.setVolume(_x-left); }
on (press) { startDrag ("", false, left, top, right, bottom); dragging = true; } on (release, releaseOutside) { stopDrag (); dragging = false; }
The startDrag()
parameters left
, top
, right
, and bottom
are variables set in a clip action.
onClipEvent(load){ top=_y; bottom=_y; left=_x-50; right=_x+50; center=_x; } onClipEvent(enterFrame){ if (dragging==true){ _parent.setPan((_x-center)*2); } }
For more information about the methods of the Sound class, see Sound class.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |