Adding the music

 < Day Day Up > 



A great new feature of Flash MX is the ability to load external MP3. sound files. You could load exter- nal movies in Flash 5 by first making the MP3. sound file into an SWF file that could load. Now you can directly load an MP3. sound file from your server.

The following steps offer a few MP3s so you can practice. These sound files are compliments of Ron and Yvonne Rockwell. (Ron wrote the Freehand section of this book.) They are original sound files. Save the jukebox.fla from the CD and the sample sound file onto your hard drive. Put them in the same folder.

  1. Open the jukebox.fla file if you've closed it from the Bonus Tutorials\jukebox folder. Now you are going to program the buttons to load the song when a user clicks them.

  2. Select button 1 and open the Actions panel (F9).

  3. In Expert mode, type the following:

    on (press) {  sound1 = new Sound();  sound1.loadSound("sound1.mp3", true);

    This bit of code starts with the on (press) event handler. Then you made a new sound object. The third line of code tells the browser to load the sound and gives the URL of the sound. The word true tells it to start playing as soon as there is enough downloaded to play.

    Now you want the title of the song and the artist name to load into your dynamic text boxes to replace the default text.

You need to send data that the title Movie Clip can access.

Set the dynamic text boxes in the jukebox with the correct data about this particular sound. When you play a sound, you want the text boxes to display the correct song name and artist. You need to change the dynamic text boxes to reflect the correct tile and artist name changes.

  1. In the right pane of the Actions pane, add the following code:

    title_name="sound1";  title_artist=" Yvonne Rockwell";
    Note 

    In the Jukebox folder, there is a folder named music. Substitute these names for the title or whatever name you'd like to use.

    title_name and title_artist are the names of the variables in the jukebox that you need to change when a song is clicked. This code sets those to dynamic text boxes to the correct name and title.

    You need to communicate with the jukebox. Remember, you have to send the artist name and song title to those dynamic text boxes located in the title Movie Clip. The jukebox is in the root; the instance name of the Movie Clip that contains the dynamic text box is title. The Movie Clip's name (title) needs to be added to the code so that the dynamic text boxes in the Movie Clip can be accessed.

  2. The Actions panel should still be open with the code you typed in Step 6. Type title. in front of the title_name and the title_artist lines of code. Press Enter and type } to close the statement. The resulting code will look as follows:

    _ title.title_name="sound1";  _ title.title_artist=" Yvonne Rockwell"; }

    The complete code in the Actions panel should like this:

    on (press) {  sound1 = new Sound();  sound1.loadSound("sound1.mp3", true);  title.title_name="sound1";  title.title_artist="Yvonne Rockwell"; }
  3. Now program the Stop button so the user can stop a sound at any time. Select the Stop button (red rectangle in center).

  4. In the Actions panel, type the following:

    on (press){  sound1.stop(); }

    This script says that when the button is pressed the new sound object of sound1 will stop. You have only to add this code one time for the S button. It works no matter which song is playing.

  5. Select button 1, and in the Actions panel, copy all the code. Select button 2 and paste into the Actions panel (Expert mode). Change the URL filename; then change the title and artist name.

  6. Save your file and test it. There is a copy of the finished version in the Bonus Tutorials\jukebox folder named jukebox_done.fla.



 < Day Day Up > 



Macromedia Studio MX Bible
Macromedia Studio MX Bible
ISBN: 0764525239
EAN: 2147483647
Year: 2003
Pages: 491

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net