View comments | RSS feed

loadMovie (MovieClip.loadMovie method)

public loadMovie(url: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: To monitor the progress of the download, use the MovieClipLoader.loadClip() method instead of the loadMovie() method.

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

A SWF file or image loaded into a movie clip inherits the position, rotation, and scale properties of the movie clip. You can use the target path of the movie clip to target the loaded SWF file.

When you call the loadMovie() method, set the MovieClip._lockroot property to true in the loader movie, as the following code example shows. If you don't set _lockroot to true in the loader movie, any references to _root in the loaded movie point to the _root of the loader instead of the _root of the loaded movie:

myMovieClip._lockroot = true;

Use the MovieClip.unloadMovie() method to remove SWF files or images loaded with the loadMovie() method.

Use the MovieClip.loadVariables() method, the XML object, Flash Remoting, or Runtime Shared Objects to keep the active SWF file and load new data into it.

Using event handlers with MovieClip.loadMovie() can be unpredictable. If you attach an event handler to a button by using on(), or if you create a dynamic handler by using an event handler method such as MovieClip.onPress(), and then you call loadMovie(), the event handler does not remain after the new content is loaded. However, if you attach an event handler to a movie clip by using onClipEvent() or on(), and then call loadMovie() on that movie clip, the event handler remains after the new content is loaded.

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

For Flash Player 8:

For Flash Player 7 and later:

For more information, see the following:

You can extend the methods and event handlers of the MovieClip class by creating a subclass.

Availability: ActionScript 1.0; Flash Player 5 - 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, JPEG, GIF, and PNG 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:///.

method:String [optional] - Specifies an HTTP method for sending or loading variables. The parameter must be the string GET or POST. If no variables are 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

The following example creates a new movie clip, and then creates child inside of it and loads a PNG image into the child. This lets the parent retain any instance values that were assigned prior to the call to loadMovie.

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.onRelease = function():Void {
    trace(this.image._url); // http://www.w3.org/Icons/w3c_main.png
}
var image:MovieClip = mc.createEmptyMovieClip("image", mc.getNextHighestDepth());
image.loadMovie("http://www.w3.org/Icons/w3c_main.png");

The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth() method.

See also

_lockroot (MovieClip._lockroot property), unloadMovie (MovieClip.unloadMovie method), loadVariables (MovieClip.loadVariables method), loadMovie (MovieClip.loadMovie method), onPress (MovieClip.onPress handler), MovieClipLoader, onClipEvent handler, on handler, loadMovieNum function, unloadMovie function, unloadMovieNum function


Version 8

Comments


No screen name said on Oct 4, 2005 at 2:10 AM :
This is the content of Humanoid.as :

dynamic class Humanoid extends MovieClip {
var head_mc:MovieClip;
var bust_mc:MovieClip;
var arm1_mc:MovieClip;
function Humanoid(_head:String, _bust:String, _arm1:String) {
loadMovie(_head, this.head);
loadMovie(_bust ,this.bust);
loadMovie(_arm1, this.arm1);
}


When I compile this file imported in a .fla one, I get the error °... type Mismatch° and it's due to the loadMovie function.
Does anybody know why?
Thanks
Andrea
king steven said on Oct 8, 2005 at 10:41 AM :
no idea why, you can however get around it by not using strict data types in the variable declaration.

//won't work
var biog:MovieClip;
this.createEmptyMovieClip("biog", 0)
loadMovie("biog.swf", biog);

//works
var biog;
this.createEmptyMovieClip("biog", 0)
loadMovie("biog.swf", biog);
specialJay said on Oct 29, 2005 at 8:01 PM :
It would be nice to see an example here of using GET and POST methods for passing variables to loadMovie.
aran.rhee said on Nov 23, 2005 at 1:56 AM :
Andrea

If you look at the parameters that loadmovie takes, you cannot pass it a reference of the movieclip you want to load into as the 2nd param. You might want to do something like this:

class Humanoid extends MovieClip
{
var head_mc:MovieClip;
var bust_mc:MovieClip;
var arm1_mc:MovieClip;

function Humanoid(_head:String, _bust:String, _arm1:String)
{
// assuming you have no movieclips already
head_mc = this.createEmptyMovieClip("head_mc", 1);
bust_mc = this.createEmptyMovieClip("bust_mc", 1);
arm1_mc = this.createEmptyMovieClip("arm1_mc", 1);
// load into our MC's
bust_mc.loadMovie(_head);
arm1_mc.loadMovie(_bust);
arm1_mc.loadMovie(_arm1);
}
}
No screen name said on Dec 5, 2005 at 12:20 PM :
Why my clip mc_1 is not showing?

this.createEmptyMovieClip ("mc_2");
mc_2._x=200;
mc_2._y=200;
loadMovie("mc_2","mc_1");
No screen name said on Aug 17, 2006 at 6:19 PM :
It seems to have a problem with masking. The masking layer has 2 frames. Frame 1 is a rectangle, and frame 2 has a circle. If you load an image on a movie clip with the masking layer and tell it to gotoAndStop(2), the loaded image disappears. Any idea around this?

~glasses248
No screen name said on Aug 24, 2006 at 12:38 PM :
function loadBio() {
var bio_mc:MovieClip = _root.createEmptyMovieClip("bio_mc", _root.getNextHighestDepth());
bio_mc._x = 109;
bio_mc._y = 188;
bio_mc.loadMovie("swfs/bio.swf");
bio_mc.backgroundInfo.text="this better work.";
}


I want to load a swf into a empty MovieClip called "bio_mc", and then send data to a textfield inside the loaded movieclip. Could someone help.

Thanks
slurpy said on Aug 25, 2006 at 3:23 PM :
this.createEmptyMovieClip ("mc_2");
mc_2._x=200;
mc_2._y=200;
loadMovie("mc_2","mc_1");

should be


this.createEmptyMovieClip ("mc_2");
mc_2._x=200;
mc_2._y=200;
mc_2.loadMovie("http://website/flashfile.swf");
sihungvo said on Aug 28, 2006 at 5:12 AM :
To find TechNotes, general troubleshooting information, and other helpful resources, go to the Macromedia Support Center.
No screen name said on Oct 10, 2006 at 8:01 AM :
I run into a problem while loading an external
movie, which is an SWF (test.swf) containing
5 keyframes, labeled sequentially, as 1,
2, 3,..., like a slide show.

My code is as the following:

//*******************
this.createEmptyMovieClip("show_swf", 0);
//
loadMovie("test.swf", show_swf); //load file
trace(show_swf._totalframes); // the number is 1.
//***********************

The file is loaded, but only frame 1 is shown.
I can not move to other keyframes by using
show_swf.nextFrame(), or show_swf.gotoAndStop(Number).
Actually, when I traced the value of
show_swf._totalframes, it gave me a number 1,
instead of 5 that is actually in test.swf.

What did I do wrong?

David.
No screen name said on Nov 15, 2006 at 4:00 AM :
hi
pls i need some help_
im loading BIG( 1440 width) external jpg into scrolling area everything seems to be ok but the result is that imporded jpg is cuted off_
when i tried swf instead of jpg there is no problem
are there some jpeg limits??
thanks
adinana said on Aug 25, 2008 at 2:21 AM :
Hi ;
I get the following error when I try to load a jpeg file online in flash lite

FTPS035: A Call to loadMovie("www.some jpeg file.com ") found, limitations might apply.

the same thing works fine if it is a flash application.

Please let me know if there are any work arounds for this

 

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/00002479.html