View comments | RSS feed

loadMovie function

loadMovie(url:String, target:Object, [method:String]) : Void
loadMovie(url:String, target:String, [method:String]) : Void

Loads a SWF, JPEG, GIF, or PNG file into a movie clip in Flash Player while the original SWF file is playing. Support for unanimated GIF files, PNG files, and progressive JPEG files is added in Flash Player 8. If you load an animated GIF, only the first frame is displayed.

Tip: If you want to monitor the progress of the download, use MovieClipLoader.loadClip() instead of this function.

The loadMovie() function lets you display several SWF files at once and switch among SWF files without loading another HTML document. Without the loadMovie() function, Flash Player displays a single SWF file.

If you want to load a SWF or JPEG file into a specific level, use loadMovieNum() instead of loadMovie().

When a SWF file is loaded into a target movie clip, you can use the target path of that movie clip to target the loaded SWF file. A SWF file or image loaded into a target inherits the position, rotation, and scale properties of the targeted movie clip. The upper left corner of the loaded image or SWF file aligns with the registration point of the targeted movie clip. Alternatively, if the target is the root Timeline, the upper left corner of the image or SWF file aligns with the upper left corner of the Stage.

Use unloadMovie() to remove SWF files that were loaded with loadMovie().

When using this function, consider the Flash Player security model.

For Flash Player 8:

For Flash Player 7 and later:

For more information, see the following:

Availability: ActionScript 1.0; Flash Player 3 - The ability to load JPEG files is available as of Flash Player 6. The ability to load unanimated GIF files, PNG files, or progressive JPEG files is available as of Flash Player 8.

Parameters

url:String - The absolute or relative URL of the SWF or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///.

target:Object - A reference to a movie clip object or a string representing the path to a target movie clip. The target movie clip is replaced by the loaded SWF file or image.

method:String [optional] - Specifies an HTTP method for sending variables. The parameter must be the string GET or POST . If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Example

Usage 1: The following example loads the SWF file circle.swf from the same directory and replaces a movie clip called mySquare that already exists on the Stage:

loadMovie("circle.swf", mySquare);
// equivalent statement (Usage 1): loadMovie("circle.swf", _level0.mySquare);
// equivalent statement (Usage 2): loadMovie("circle.swf", "mySquare");

The following example loads the SWF file circle.swf from the same directory, but replaces the main movie clip instead of the mySquare movie clip:

loadMovie("circle.swf", this);
// Note that using "this" as a string for the target parameter will not work
// equivalent statement (Usage 2): loadMovie("circle.swf", "_level0");

The following loadMovie() statement loads the SWF file sub.swf from the same directory into a new movie clip called logo_mc that's created using createEmptyMovieClip():

this.createEmptyMovieClip("logo_mc", 999);
loadMovie("sub.swf", logo_mc);

You could add the following code to load a JPEG image called image1.jpg from the same directory as the SWF file loading sub.swf. The JPEG is loaded when you click a button called myBtn_btn. This code loads the JPEG into logo_mc. Therefore, it will replace sub.swf with the JPEG image.

myBtn_btn.onRelease = function(){
 loadMovie("image1.jpg", logo_mc);
};

Usage 2: The following example loads the SWF file circle.swf from the same directory and replaces a movie clip called mySquare that already exists on the Stage:

loadMovie("circle.swf", "mySquare");

See also

_level property, loadMovieNum function, loadMovie (MovieClip.loadMovie method), loadClip (MovieClipLoader.loadClip method), unloadMovie function


Version 8

Comments


William_Donelson said on Mar 1, 2006 at 10:33 PM :
IMPORTANT NOTE: You may NOT use or access the resulting movie from "loadMovie...)" until AFTER the movie has loaded !!! This is unclear from the documentation above.

Example:
this.createEmptyMovieClip("myTitle", 999);
loadMovie("nssTitle.swf", myTitle);
_root.onEnterFrame = function()
{
if (myTitle.getBytesTotal() == myTitle.getBytesLoaded() && myTitle._width != 0)
{
myTitle._x = 320;
myTitle._y = 60;
myTitle.theText.text = "Hospitality in the Court of King Arthur";
delete _root.onEnterFrame;
}
};
No screen name said on Mar 8, 2006 at 12:06 PM :
You've got an error in the documentation for loadMovie. The URL isn't relative to the Flash movie in a browser (unless the HTML page and the SWF file are in the same directory). It's relative to the HTML page CALLING the SWF file. I've found this out the hard way.
Joseph Russavage said on Apr 8, 2006 at 4:53 PM :
I am unclear how to use loadMovie to send a variable from one movie to another. I have a movie "Map.swf" from which the user chooses a starting and ending location. The starting and ending location are recorded as variables, so I have a string variable that contains text like "startPlace="ALDER"&endPlace="UPF"". The user selects "Show Route" and a new movie "RouteMap.swf"is loaded with loadMovie. How do I pass the content of my variables startPlace and endPlace into the variables with the same name in RouteMap.swf?
No screen name said on Nov 15, 2006 at 2:01 PM :
Is there anyway to use loadmovie to load any other type of image file other than jpg?
kyle mcknight said on Dec 17, 2006 at 9:50 AM :
Is there a way to srhink a jpg down to fit inside of a movie clip? i want a 400x400 picture to fit into a 100x100 movieclip.
kyle mcknight said on Dec 17, 2006 at 9:55 AM :
is there a way to load a jpg into a movie clip and have it resize down to the movie clip size? i need to do that. i'd rather not have to do it outside of flash
MattIcovia said on May 9, 2007 at 12:37 PM :
We've got a pattern where we load .SWF objects from disc, and the solution isn't scaling well. I'm looking at how I can store all the SWF's in one master SWF, load it once, and then loadMovie from that swf into our main swf.
Soumik Dasgupta said on May 29, 2007 at 10:07 PM :
If the CODE 1 can bring the external swf why cant the CODE 2?? I am just giving the path from the variable URL...

CODE 1

_root.link = 1;
//url = "movie1.swf";
loadMovie("movie1.swf", 2);


CODE 2

_root.link = 1;
url = "movie1.swf";
loadMovie(url, 2);
Max Damage said on Jun 6, 2007 at 2:56 AM :
@kyle mcknight: you can use a scaled down movieclip (25%) to obtain 100x100 from 400x400

Do I have any kind of control on the smoothing of a loaded jpg?
kyle mcknight said on Jun 7, 2007 at 10:54 AM :
i tried scaling down the movie clip, but the image stayed the same size so you onl saw a quarter of the image at say 25% scale. i havfent worked on this project in a while, so cant remember all the details. does it mater if you resize then load the image, or load then resize?
juankpro said on Aug 1, 2007 at 8:48 AM :
Loaded images cannot be resized before they are loading with the _width and _height. You can modify the _xscale and _yscale properties. Or wait until it is loaded.

To wait you have to write an onEnterFrame event or use the new MovieClipLoader which is more powerful.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001739.html