Modifications

As we discussed before, it's much easier to reference ID3 tag data in Flash Player 7. This Player supports v2.2 and v2.4 ID3 tags, which are stored at the beginning of the MP3 file rather than at the end.

Flash MX 2004 only!

As you can only produce Flash Player 7 SWF files using Flash MX 2004, this modification is suitable for Flash MX 2004 only.

To edit this effect, locate mp3?mx2004.fla in the code archive.

We need only make a couple of simple modifications to the movie to allow Flash MX 2004 to read ID3 v2.2 and 2.4 tag information.

  • Select the first frame of the Actions layer, then locate and delete the playTrack function from the Actions Panel. It's no longer needed!
  • Replace the onPress event handler code for the randomPlayer movie clip with the following code:
  • Example 5.13. mp3?mx2004.fla Actions : 1 (excerpt)

    randomPlayer.onPress = function ()
    {
            stopAllSounds ();
            var trackNo = randomBetween (0, trackInfo.length - 1);
            var track = new Sound ();
            track.onID3 = function ()
            {
                    trackID3Info.text = "";
                    trackID3Info.text += "Title: " + track.id3.TIT2 + newline;
                    trackID3Info.text += "Artist: " + track.id3.TPE1 + newline;
                    trackID3Info.text += "Album: " + track.id3.TALB + newline;
                    trackID3Info.text += "Year: " + track.id3.TYER + newline;
                    trackID3Info.text += "Comments: " + track.id3.COMM +
                    newline;
            };
            track.loadSound (tracklist[trackNo], true);
    };

     

    This code is essentially the same as before, but it uses an event handler to process the ID3 tag information rather than calling a function every half-second to check for it.

    After we've created the new Sound object (track), we reference a new event handler, called onID3, which is available in Flash Player 7. This is invoked when new ID3 data is detected for a loaded MP3 file, which means that we don't need to confirm that the MP3 file has completely loaded before we check for the ID3 tag data. Once the onID3 event handler is invoked, we can proceed to populate the trackID3Info dynamic text field with the ID3 2.0 tags. It's as simple as that!

    ID3 Reference

    For a complete listing of supported ID3 tags within Flash MX 2004, search for Sound.ID3 in the Help Panel.

  • Save and preview your work.
  • Now, when you click the randomPlayer movie clip, the MP3 file starts to play and the ID3 tag data is displayed in the dynamic text field almost instantly. You no longer need to wait for the MP3 file to load completely as you did in the previous example.

    Conclusion

    Who said that all you can do with sound clips is play them? Certainly not me! I hope that we've covered enough material within this chapter to fuel your desire to create some really interesting sound-based interfaces, experimental effects, and other items.

    It's now time to see what we can accomplish using video effects in Flash!

    Excerpted from The Flash Anthology: Cool Effects & Practical ActionScript written by Steve Grosvenor and published by SitePoint. Learn to create and customize dozens of effects, work with external data, produce Flash charts & graphs, create Flash Forms, use CSS in Flash and more. Click here for 3 free sample chapters. Reproduced with permission.

    The book contains a total of 10 chapters that provide over 60 ActionScipted solutions to common problems in Flash. Every solution you'll ever need for your Flash projects, from text and video effects, to debugging and using external data in your applications, is covered in this 455-page reference. All the code included in the book is available in a free downloadable archive.

    For more information, see the book page.