Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now we'll talk about using Flash to access ID3 tag information inside of Mp3 files. If you're following along, I'm working in 07_ID3_Tags.fla, in the 07 folder, in the Chapter 9 folder, in the Exercise Files folder. The first thing we're going to do is our favorite process of connecting this file to our class file, so I'm going to click the Publish Settings button at the bottom of the Property Inspector and then in the Flash tab I'm going to click the Settings button near ActionScript version, I'm going to select the current class path, remove it, browse to a new class path.
In the Chapter 9 folder I'm going to find the 07 folder, in the Start folder, I'm going to select the Classes folder and then click Choose button, click the OK to close ActionScript 3.0 settings and click OK to close the Publish Settings window. And now we're connected so let's open up our class file that we are going to be working in for this file. So choose File, Open and we're going to be working with our SoundLoader class file, so in the Chapter 9 folder find the 07 folder in the Start folder and then in the Classes folder lets just navigate all the way down untill we find all of our Class files and we'll open up the SoundLoader.as file and inside the constructor function of this file, and I'm talking about line 18 through 25 in my code, right below the loader.addEventListener, Event.Complete line of code we'll type loader.addEventListener and event is going to be event.ID3 all caps and we're going to put comma and a space and we're going to run a function called id3Ready with capital R.
Now this is one thing that I absolutely love about ActionScript 3.0. We simply add an EventListener to our sound object, and the event is Event.ID3, then we simply run a function and we have a function that runs as soon as our ID3 Tags are accessible and actually accessing the ID3 Tags is fairly simple as well. So scroll down, to the bottom of your code, right below where we've created the songLoaded function. Now we crate another private function and the function is going to be id3Ready with capital R. It's going to receive an event with the data type of Event and inside the curly braces we'll talk about how to access the ID3 Tag information.
Let's first create a variable called artist, and this will represent the artist for the song and the data type is going be a string and we'll set that equal to loader and that's our sound object. Now once ID3 tags are ready to work with, then those tags are held inside the id3 property of the sound class. Now we can access the artist information through this id3 property, so we type loader.id3.artist, and that gives us the artist for this particular Mp3 file. Lets go to the next line and create another variable called songName, with a capital N and the data type will also be a string, also set that equal to loader.id3.songName with a capital N.
That's how we access the name of the song. Now let's take a look at putting this data inside of the text field in our Mp3Player. Remember that our Mp3Player class is connected to our FLA file and thus knows all of the instances on the stage in our FLA file. So we can access our text fields on the stage through that Mp3 object. Now in this class the Mp3 object is stored in a variable called Music Player. Let's go to the next line of code and type musicPlayer, if you remember inside of the MP3 player class file that we created, there's a property in there called artistText and that represents the Artist Text field so type .artistText with a capital T and that gets us to our artistText field, so type .text and this will referre to the text property of that text field and we'll set that equal to artist.
And on the next line, let's type musicPlayer.songText.text equals and were going to put the song name in quotes, so I'm going to type an open quote and then a backslash (/). / is an escape character in Flash, what that does is it ignores the next character. So if I type a quote there, then Flash will not think that I'm closing a string because of this backslash character. Now I'm going to type another close quote that closes out the entire string.
So inside of our string I have a backslash and a quote, and all you're going to see in Flash is just the quote. The backslash ignores characters that are key characters in ActionScript, like quotes. So type space,+space, songName plus and now we'll do the same things so type quote, backslash, quote, quote and a semicolon. So than our song text field will display the songName in qoutes. Now let's test the movie and see our ID3 Tag information being displayed in our Mp3Player.
Choose File, Save to save this file and then we'll test the movie using Cmd+Return on the Mac or Ctrl+Enter on the PC. In Mp3 Player you can see the artists name, is WedgeKase and the song is Chad Freed in quotes. I'll close the preview window, and that's looking how to work with ID3 Tags in Flash but you may have some more questions as to what ID3 tags, can we access in Flash and how do you access them. The best way to find that out is through Flash Help. To access that information, I'm going to highlight id3 in my code then I'm going to press F1 on my keyboard to open Flash Help. Flash Help then opens and tells me information about the ID3 property and what ID3 Tag information I can access.
So you scroll down in your code. You can read all about what ID3 Tags you can access and what values you can get. so close the Help window and there's a look at working with ID3 Tags in Flash.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 59565 Viewers
61 Video lessons · 92390 Viewers
82 Video lessons · 104121 Viewers
56 Video lessons · 106928 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.