Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 259 260 261 262 263 264 < 265 > 266 267 268 269 270 271 .. 419 >> Next

Tip You can, however, loop a sound resource, which enables the sound to play for indefinite
periods of time. See the description of the start() method later in this chapter.
The following code displays the length of a sound resource in the Output panel. This code uses methods described later in this chapter:
var snd_1:Sound = new Sound(); snd_1.attachSound("carHorn");
trace("carHorn is " + snd_1.duration + " milliseconds in length."); trace("carHorn is " + (snd_1.duration/1000) + " seconds in length.");
Retrieving the Sound's Current Time with Sound.position
The position property of the Sound class returns the current playback time (in milliseconds). For example, if a 10-second sound has played back from three seconds, the position property returns 3,000. The following code creates and plays a Sound object, and creates a Mouse l istener that enables a mouse click anywhere in the movie to display the current position value (in seconds) in the Output panel:
var snd_1:Sound = new Sound();
snd_1.attachSound("soundtrack");
snd_1.start();
this.onMouseDown = function():Void {
trace("Current position:\t" + (snd_1.position/1000) + " seconds");
};
Mouse.addListener(this);
570 Part VI ¶ The Audio and Video Classes
For more information on the Mouse l isteners, refer to Chapter 19.
Looped sounds return a value relative to the native length of the sound resource. For example, if you loop a 10-second sound three times, the position property always returns values between 0 and 10,000.
Reading an MP3 File's ID3 Tags with Sound.id3
You can use the id3 property of a Sound object to retrieve information about an MP3 file loaded into the Sound object. ID3 tags contain information about the MP3 file. You can read these tags after the ID3 information has loaded (see the Sound.onID3 coverage later in this chapter) or after the MP3 file has loaded (see the Sound.onLoad coverage).
ID3 information can be stored as ID3 1.0 or ID3 2.0 (or later). If your MP3 file uses ID3 1.0 tags, you can use the following properties in ActionScript:
¶ Sound.id3.comment
¶ Sound.id3.album
¶ Sound.id3.genre
¶ Sound.id3.songname
¶ Sound.id3.artist
¶ Sound.id3.track
¶ Sound.id3.year
For example, the following code shows the MP3ís song name, as stored in an ID3 v1.0 tag, in a TextField instance named tDisplay:
var sndInstance:Sound = new Sound(this); sndInstance.onID3 = function(){
createTextField("tDisplay", 1, 20, 20, 300, 30); tDisplay.text = "Title: " + this.id3.songname;
};
sndInstance.loadSound("atmospheres_1.mp3", true);
If your MP3 file uses ID3 v2.0 (or later) tags, several ID3 tags are available, too numerous to list here. Some common ones are the following:
¶ Sound.id3.COMM (comment)
¶ Sound.id3.TALB (album)
¶ Sound.id3.TCON (genre)
¶ So und.id3.TIT2 (songname)
¶ Sound.id3.TPE1 (artist)
¶ So und.id3.TRCK (track number)
¶ Sound.id3.TYER (year)
Chapter 23 ¶ The Sound Class
571
You can find the complete specification for all ID3 v2.0 tag names at www.id3.org/ i d3v2.3.0.html#sec4. Using the previous example of reading ID3 v1.0 tags, you simply need to modify the name of the id3 property you want to use for ID3 v2.0 (or later) tags. Note that your MP3 file must contain these tags in order for the Flash Player to read them:
var sndInstance:Sound = new Sound(this); sndInstance.onID3 = function(){
createTextField("tDisplay", 1, 20, 20, 300, 30); tDisplay.text = "Title: " + this.id3.TIT2;
};
sndInstance.loadSound("atmospheres_1.mp3", true);
Flash Player 7 automatically copies the values of ID3 v1.0 tags to their ID3 v2.0 equivalents.
As such, you should be able to consistently use ID3 v2.0 references in your ActionScript code, provided that an equivalent ID3 v1.0 tag exists in your loaded MP3 file.
Loading Methods of the Sound Class
The following methods can be used to load or monitor the loading of a sound resource into a Sound object. These methods are presented in the order in which they are commonly used:
1. Attach or load a sound into a Sound object.
2. Monitor the download of the sound resource (optional ó applies only to loaded sounds, not attached sounds).
3. Execute a function when the sound resource is done loading (optional ó applies only to loaded sounds, not attached sounds).
Using an Exported Sound from the Library
The Sound.attachSound() method enables you to link a sound in the movieís Library to a Sound object in the movie. The only argument for the method is a string value that refers to the sound assetís linkage identifier. To set a soundís linkage identifier, right-click (or Control-click on the Mac) the sound in the Library panel, and choose Linkage. In the Linkage Properties dialog box (shown in Figure 23-6), select Export for ActionScript and assign a name in the Identifier field.
Linkaqe Properties
[dertlta bgSorrf
AS 2.0 Oass:
Linkage: ¬ Export for ActionScnpt
f~l Export for runtime sharing
M Import for runtime shamg ¬ Export m fcst frsme
Web
^Resource
Tip
Figure 23-6: The Identifier name is used as the argument of the attachSound( ) method.
Previous << 1 .. 259 260 261 262 263 264 < 265 > 266 267 268 269 270 271 .. 419 >> Next