Loading External SWF file

The loadMovie() function is a little function that loads external .swf (also: .jpg, .png, etc.) into a movieclip within the main movie. One advantage of this is that content is not loaded together with the main movie, which makes your swf smaller, and another is that by changing one swf you can alter many other swfs - useful, for example, when dealing with logos.

 

example 1

Imagine you're making a Flash photoslider of some sort, you certainly wouldn't like to cram all the photos into just one swf file and export it like that. The reason for that is you would create a huge file that no-one would like to download. *

EXAMPLE 2

[If I ever decide to change my logo, this one will change too]

 

TIP
If you're loading an external image and you want it's background to be transparent, you should use the .png format, which handles Alpha channel.


Syntax

The syntax for loadMovie() is simple:

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

So, an example might look something like below:

loadMovie("load_me.swf","box12");

This line of code loads a file called load_me.swf (must be in the same folder as the project you're working on), into a movieclip called box12. We did not use the third parameter because it's not compulsory.

Changing properties

Once you load your movieclip, surely you would like it scale it down or up, move it or apply some changes to it. Because content you load into the movieclip replaces the movieclip, it also inherits its properties. Which is why you should always refer to the intance name of the Movieclip. So, your code might be:

loadMovie("load_me.swf","box12");
_root.box12_.x = 0; // changing the x coordinate to (null?)
_root.box12_.y = 0;
_root.box12._alpha = 30 // taking alpha down to 30

TIP
In accorance with what is written above, if you wanted to change the shape of box12, you should never scale the symbol itself, rather you should enter it and once inside apply the necessary changes.

Unloading a Movieclip

Sometimes you may find yourself in need to get rid of loaded content. That can be done in several ways, the easiest of which is using unloadMovie(). What this function does is remove loaded content completely from the scene, as in the example below:

 

 

I hope you enjoyed this tutorial. Also, you can find more of them here. Have a fabulous day.

* Another issue is that the only way to edit the photos would be opening your .fla file and re-exporting it, which is a rather daunting task.

 

Average: 3.5 (35 votes)