About loading and using external MP3 files
599
Loading an MP3 file
suppose you’re creating an online game that uses different sounds that depend on what level
the user has reached in the game. The following code loads an MP3 file (song2.mp3) into the
game_sound
Sound object and plays the sound when it IS completely downloaded.
To load an MP3 file:
1.
Create a new FLA file called
loadMP3.fla
.
2.
Select Frame 1 on the Timeline, and then type the following code in the Actions panel:
var game_sound:Sound = new Sound();
game_sound.onLoad = function(success:Boolean):Void {
if (success) {
trace("Sound Loaded");
game_sound.start();
}
};
game_sound.loadSound("http://www.helpexamples.com/flash/sound/song2.mp3"
false);‘
3.
Select Control > Test Movie to test the sound.
Flash Player supports only the MP3 sound file type for loading sound files at runtime.
For more information, see
Sound.loadSound()
,
Sound.start()
, and
Sound.onLoad
in the
ActionScript 2.0 Language Reference
. For information on preloading MP3 files, see
“Preloading
MP3 files” on page 599
. For information on creating a progress bar animation when you load
a sound file, see
“Creating a progress bar for loading MP3 files with ActionScript”
on page 627
.
You can find a sample source file that loads MP3 files, jukebox.fla, in the Samples folder on
your hard disk. This sample demonstrates how to create a jukebox by using data types, general
coding principles, and several components.
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\Components\Jukebox.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/Components/Jukebox.
Preloading MP3 files
When you preload MP3 files, you can use the
setInterval()
function to create a
polling
mechanism
that checks the bytes loaded for a Sound or NetStream object at predetermined
intervals. To track the downloading progress of MP3 files, use the
Sound.getBytesLoaded()
and
Sound.getBytesTotal()
methods.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...