User Guide
Loading external MP3 files 297
The following code loads the JPEG image flowers.jpg into the movie clip instance image_clip:
image_clip.loadMovie("flowers.jpg");
For more information about these methods, see loadMovie(), loadMovieNum(), and
MovieClip.loadMovie() in Flash ActionScript Language Reference.
For more information about loading external SWF and JPEG files, see the next section.
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 to that of the loaded SWF
file. This can sometimes cause 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 208. For more information about using
_root and _lockroot, see
Chapter 3, “Using scope,” on page 95.
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
System.security.allowDomain() in Flash ActionScript Language
Reference and “Flash Player security features” on page 288.
Loading external MP3 files
To load MP3 files at runtime, you use the loadSound() method of the Sound class. First, you
create a Sound object, as shown in the following example:
var song1_sound:Sound = new Sound();
Then you 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 play 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);