Flash MX MP3 player, Pt.1

source: http://www.thegoldenmean.com

3 — The Data Source

If you haven’t done so already, you can download the files for this tutorial here.

Why?

Since one of our design goals was to make the movie such that we never need to edit the .fla again, there needs to be some mechanism to inform the movie what music it has available. That mechanism will be an external xml file. This file will simply consist of the titles which will show up in the menu and the paths to the actual MP3 assets.

The form of the xml

Launch your favorite text editor and create a new blank document. The start and finish are as follows:

<?xml version="1.0" ?>
   <songs>
	
   </songs>

This establishes the xml document with a first child of “songs”. Save this text file to the same directory you created for this project. Flash will be looking for the file in the same directory as the .swf movie.

The form of the entire document will follow this model:

<?xml version="1.0" ?>
     <songs>
          <song display="Menu entry" url="path to asset" />
     </songs>

To make it more clear, the xml file I have on my own site at the time of this writing is as follows:

<?xml version="1.0" ?>
     <songs>
          <song display="Delta Fog" url="Delta_Fog.mp3" />
          <song display="Journeys End" url="Journeys_End.mp3" />
          <song display="Quiet Storm" url="Quiet_Storm.mp3" />
          <song display="Shubert, Mass No. 2, Kyrie" url="mass.mp3" />
          <song display="Thats What I Like" url="Thats_What_I_Like.mp3" />
          <song display="solo cello" url="cello.mp3" />
     </songs>

Is the pattern clear? Each “song” node has two attributes: “display” and “url”. “display” is what the user will see in the movie’s menu. “url” is the name of and path to the actual MP3 file. You would (obviously I hope) substitute your own titles and file names. Don’t forget the closing slash at the end of each line, since the form of these nodes is “self–closing.”

Note: The above example assumes you have all the MP3 files in the same directory as the swf. If you have a different directory structure, you will need to modify the “url” attribute. Let’s say that in an effort to keep things organized on your server you decide to keep all your music assets in a directory named “mp3.” If your .swf file is still in the “music” directory and if the“music” and “mp3” directories are at the same level, your “url” path would have to change. In this scenario we might write

<?xml version="1.0" ?>
     <songs>
          <song display="Delta Fog" url="../mp3/Delta_Fog.mp3" />
          etc...
     </songs>

Now that we have our xml file written, let’s move on to Page Four wherein we return to the .fla file and begin coding functions in earnest.

go to page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
divider ornament

--top--