Turn your computer into a jukebox with Flash.
To create a MP3 player in Flash--a Flash application that lets you play different songs--you can use the latest version of the Flash programming languages, known as Actionscript 3.0 or AS3 for short.
The use of AS3 makes it a straight forward task to create a MP3 player. All you need to do is add buttons to the screen, label them with the song title and write the code for each button. The AS3 code for each button will instruct Flash to retrieve a specific song and play it.
Instructions
1. Import your music MP3 files into your Flash library. Select "File" from the main menu, select "Import" from that pull-down menu, then "Import To Library" from its pull-down menu. Assign a Sound object variable name for each music file. Use this variable name in the AS3 code that you will write to control the playing of each song.
2. Create control buttons. For each song you want to include in your Flash MP3 player, add a button to the stage. First draw a rectangle with the Flash rectangle tool. Then, with the rectangle still selected, select "Modify" from the main menu. Select "Convert to Symbol." Select "MovieClip" from the list box in the Convert to Symbol dialog box. Use the default symbol name. Close the symbol dialog box and select "Properties" from the Windows pull-down menu. Give the rectangle an instance name, for example, "bluesbutton." Repeat the process for each song.
3. Write the AS3 code to play each song. From the main menu, select the "Window" option. Select "Action" on its pull-down menu. Type the code for each button into the action window that appears.
Write the code for each button you've created. Write the code so that it will include an addEventListener instruction and a function statement. Associate each addEventListener statement with each button. Associate each function statement with each song. Write the code so that the user can select a song with the mouse. The user will position the cursor over the button and then press the left mouse button to play the song. Also use the "play" method, to play each sound. Place the play instruction so that it will execute when the function statement is called with the addEventListener method.
For a button named bluesongs, and a song named firstbluesong, AS3 code could be written as:
bluesongs.addEventListener(MouseEvent.CLICK, bluesplay)
function bluesplay (songevent:MouseEvent): void {
firstbluesongs.play();
}
4. Add a stop button by adding a new layer to the timeline. Select the layer icon on the timelime panel to do this. Label this timeline layer "Stop." Again create a button from the library. Also write AS3 code that will assign actions to stop the song that is playing. Use the "stopAll" method with the SoundMixer class statement to do this. Write the code so that it is similar to the play code previously written.
For a stop button named stopblues, the AS3 code could be written as:
stopblues.addEventListener(MouseEvent.CLICK, songsstop)
function songsstop (songevent:MouseEvent): void {
SoundMixer.stopAll();
}
5. Test your player. Select "Control" from the main menu. On the pull-down menu that appears, select "Test Movie." Select each music button and see if it plays the right song or any song at all. Select the "Stop" button to see if it works. If the buttons don't work correctly, recheck your code.
Related posts
Instructions For a Centon MP3 PlayerCenton MP3 players are compact electronic devices that store and play back your music while on the go. In order to store your music on the portable Centon devic...
Convert iTunes files to MP3 files so you can play them on on MP3 players other than iPods.Files purchased from iTunes are in a special format that plays only on iPods and on iTunes software. Howev...
Windows Media Player comes as the default media player in all versions of Microsoft Windows operating system, including Windows Mobile. Windows Media Player Mobile will let you play your songs and...
Create a Flash Movie Player With Flash CS4Adobe Flash CS4 has become a favorite tool for web developers who want to create rich interactive media experiences for people who visit Flash-enabled web...
MP3 players allow you to carry hundreds or even thousands of songs on one tiny hard drive. With a few clicks, you can navigate through an entire music collection while on the go and move seamlessl...