Tags

Activity Industry Sector
Arts, Media & Entertainment

Activity Originally Created By: Courtney Paulos

Guided Practice

Part of Lesson Plan: Flash Apps: Building an Embeddable Sound Player Part 1 of 5

Activity Overview / Details

 

 

Playing an Internal Sound File

  1. 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.

AS3 Sound Class

 

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.

Linkage Window - AS3 Sound

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:

var mySound:Sound = new MyFavSong();
mySound.play();
 
10.   Have students type the above code into theor actionscript panel.
 
Teacher explains...
 
Explain to the class that the Sound Class .play() method is used to play a sound. By default it plays the sound from its beginning, however they may start it from any other point by specifying the starting to position in milliseconds (Example: mySound.play(150)).

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."

Sound and FLA Same Directory

  1. Have students try this by making a new folder on their desktop, an name it "my song".
  2. Next, have them make a flash document.
  3. Have them title their document "myFLA" and save it to their new folder.
  4. 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:

var mySound:Sound = new Sound();
mySound.load(new URLRequest("myFavSong.mp3"));
mySound.play();
 
As they type the code, explain that the Sound Class .load() method is used to load an external .mp3 file. The URL must be specified as an instance of the URLRequest Class.

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 Panic_ At The Disco_ The Ballad Of Mona Lisa.mp3 [ Download ]