![MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual Download Page 195](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-actionscript/flash-mx-2004-actionscript_reference-manual_3378897195.webp)
Loading external MP3 files
195
About loaded SWF files and the root Timeline
The ActionScript property
_root
specifies or returns a reference to the root Timeline of a SWF
file. If you load a SWF file into a movie clip in another SWF file, any references to
_root
in the
loaded SWF file resolve to the root Timeline in the host SWF file, not that of the loaded SWF
file. This can sometimes lead to unexpected behavior at runtime, for example, if the host SWF file
and the loaded SWF file both use
_root
to specify a variable.
In Flash Player 7 and later, you can use the
MovieClip._lockroot
property to force references to
_root
made by a movie clip to resolve to its own Timeline, rather than to the Timeline of the
SWF file that contains that movie clip. For more information, see
“Specifying a root Timeline for
loaded SWF files” on page 123
.
About accessing data in loaded SWF files
One SWF file can load another SWF file from any location on the Internet. However, for one
SWF file to access data (variables, methods, and so forth) defined in the other SWF file, the two
files must originate from the same domain. In Flash Player 7 and later, cross-domain scripting is
prohibited unless the loaded SWF file specifies otherwise by calling
System.security.allowDomain()
.
For more information, see
“Flash Player security features” on page 188
and
System.security.allowDomain()
in
Chapter 12, “ActionScript Dictionary,” on page 205
.
Loading external MP3 files
To load MP3 files at runtime, use the
loadSound()
method of the Sound class. First, create a
Sound object:
var song_1_sound = new Sound();
You then use the new object to call
loadSound()
to load an event or a streaming sound. Event
sounds are loaded completely before being played; streaming sounds are played as they are
downloaded. You can set the
isStreaming
parameter of
loadSound()
to specify a sound as an
event sound or a streaming sound. After you load an event sound, you must call the
start()
method of the Sound class to make the sound play. Streaming sounds begin playing when
sufficient data is loaded into the SWF file; you don’t need to use
start()
.
For example, the following code creates a Sound object named
classical
and then loads an
MP3 file named beethoven.mp3:
var classical:Sound = new Sound();
classical.loadSound("http://server.com/mp3s/beethoven.mp3", true);
In most cases, set the
isStreaming
parameter to
true
, especially if you’re loading large sound
files that should start playing as soon as possible—for example, when creating an MP3 “jukebox”
application. However, if you’re downloading shorter sound clips and need to play them at a
specified time (for example, when a user clicks a button), set
isStreaming
to
false
.
To determine when a sound has completely downloaded, use the
Sound.onLoad
event handler.
This event handler automatically receives a Boolean (
true
or
false
) value that indicates whether
the file downloaded successfully.
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...