ActionScript can be used to play back sound files embedded within an FLA's library. The sound must have a unique class name associated with it.
In this recipe, we will cover how to play such embedded sounds.
From the book's code bundle, open chapter12\recipe5\recipe.fla
into Flash Professional and use it as a starting point.
The embedded sound from the Embedding audio recipe can be found in the FLA's library and has a class name of SoundEffect
linked to it.
Also, sitting on the stage is a button named playBtn
. We will play the embedded sound whenever this button is pressed.
Perform the following steps to play the sound associated with the SoundEffect
class:
Create a document class and name it
Main
.Import the
MouseEvent
class and listen forplayBtn
being pressed:package { import flash.display.MovieClip; import flash.events.MouseEvent; public class Main extends MovieClip { public function Main() { playBtn.addEventListener(MouseEvent...