Part of Lesson Plan: Flash Apps: Building an Embeddable Sound Player Part 1 of 5
Activity Overview / Details
Playing an Internal Sound File
- To follow along, have students download this .mp3 file to their computers.
Explain to students the following...
"Flash is capable of only playing .mp3 files and no other sound format.
Playing an .mp3 file is an easy task that can be performed using the Sound Class. The Sound Class can play internal sounds (mp3 files imported into an FLA file) or external sounds (mp3 files loaded by the SWF at run time). We are going to start by playing an internal .mp3 file imported into the Flash movie."
2. Once students have their mp3 file downloaded to their computers, have them open up Flash and create a new FLA in AS3 Format,
3. Then have students go through File>Import>Import to Library, browse for their .mp3 file and then click on Open.
4. Once students have their .mp3 imported, have them open their library (Ctrl+L) to find their sound file in there.
5. Explain that they are going to make this file available for ActionScript by editing its Linkage properties
Have students...
6. right-click the sound file, select Linkage to open up the linkage window.
7. Check the box for Export for ActionScript and change the Class name to MyFavSong.
8. Press OK,
They should get the same warning message they get for creating any Class with external definition file. Simply press OK to continue. That should export their sound file as an ActionScript Class called MyFavSong.
Explain that they now have their .mp3 file readily available for ActionScript. It is time to start coding the ActionScript.
9. Right-click the only frame they have on the timeline and select Actions to open up the Actions panel.
Teacher explains...
Explain that to play their sound they need to create a new instance of their sound class and then use the Sound Class method .play() to play it. The code below is pretty self explanatory:
mySound.play();
11. Have students test their movie now ( Ctrl+Enter) to hear their sound file playing! (they love this by the way)
Playing an External Sound File
Explain to students...
"Playing an external sound file is easier than playing an internal sound file because you are not required to import your file or create a class out of it.
You can create a new FLA for this version, save your FLA somewhere on your desktop, then put your .mp3 file in the same folder, and rename it to myFavSong.mp3."
- Have students try this by making a new folder on their desktop, an name it "my song".
- Next, have them make a flash document.
- Have them title their document "myFLA" and save it to their new folder.
- Next, students need to rename their .mp3 file to " myFavSong.mp3" and place the newly-renamed .mp3 file into their "my song" folder
Now back to the FLA, have students open up the Actions panel to start coding.
Teacher explains...
Explain they are simply going to create a new generic instance of the Sound Class, and then will use the .load() method to load the external file. Finally they will use the .play() method to play the sound.
5. Have the students open their actions panel and type the following code:
mySound.load(new URLRequest("myFavSong.mp3"));
mySound.play();
6. They can test their movie (ctrl + enter) now to hear their sound playing!
Materials / Resource
Panic_ At The Disco_ The Ballad Of Mona Lisa.mp3
[
Download
]




