196
Chapter 11: Working with External Media
For example, suppose you’re creating an online game that uses different sounds depending
on what level the user has reached in the game. The following code loads an MP3 file
(blastoff.mp3) into a Sound object named
gameSound
, and then plays the sound when it has
completely downloaded:
var gameSound = new Sound();
gameSound.onLoad = function (loadedOK) {
if(loadedOK) {
gameSound.start();
}
}
gameSound.loadSound("http://server.com/sounds/blastoff.mp3", false);
For sound files, Flash Player supports only the MP3 sound file type.
For more information, see
Sound.loadSound()
,
Sound.start()
, and
Sound.onLoad
in
Chapter 12, “ActionScript Dictionary,” on page 205
.
Reading ID3 tags in MP3 files
ID3 tags are data fields added to an MP3 file that contain information about the file, such as the
song name, album name, and artist name.
To read ID3 tags from an MP3 file, use the
Sound.ID3
property, whose properties correspond to
the names of ID3 tags included in the MP3 file being loaded. To determine when ID3 tags for a
downloading MP3 file are available, use the
Sound.onID3
event handler. Flash Player 7 supports
version 1.0, 1.1, 2.3, and 2.4 tags; version 2.2 tags are not supported.
For example, the following code loads an MP3 file named favoriteSong.mp3 into the Sound
object named
song
. When the ID3 tags for the file are available, a text field named
display_txt
displays the artist name and song name.
var song = new Sound();
song.onID3 = function () {
display_txt.text = "Artist: " + song.id3.TCOM + newline;
display_txt.text += "Song: " + song.id3.TIT2);
}
song.loadSound("mp3s/favoriteSong.mp3, true");
Because ID3 2.0 tags are located at the beginning of an MP3 file (before the sound data), they
are available as soon as the file starts downloading. ID3 1.0 tags, however, are located at the end
of the file (after the sound data) and thus aren’t available until the entire MP3 file has
finished downloading.
The
onID3
event handler is called each time new ID3 data is available. This means that if an MP3
file contains ID3 2.0 tags and ID3 1.0 tags, the
onID3
handler will be called twice, because the
tags are located in different parts of the file.
For a list of supported ID3 tags, see
Sound.ID3
on page 629
.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...