| Loading an external movie into
Flash
There are two methods of loading external movies into Flash:
Loading into an empty movie clip (mc):
empty.loadMovie("externalmovie.swf");
The above example loads the movie "externalmovie.swf" into
a movie clip called empty.
or loading into another level:
loadMovieNum("externalmovie.swf", "_level1");
The above example loads a movie called externalmovie.swf into level1.
I will explain more about levels and target paths in another tutorial,
which will hopefully be completed this week.
A quick primer:
When your movie loads, it loads in _level0. If you load a movie into
_level1, it will load on top of the current movie but won't unload the
current movie - just appear as though it's been placed on top.
If you then load another mover into _level2 - that movie will load on
top of the movie in _level1, but won't unload it. If you load a movie
into _level0, it will replace the main movie - ie. unload it.
End of primer.
This
tutorial will concentrate on how to load an external movie into a movie
clip. You can learn more about loading into levels in the next one.
Open a new file in Flash.
Press F11 to bring up the library.
Click on the plus sign in the bottom left of the window to create a new
symbol.
Select Movie Clip and call it "empty".
When you click ok you'll be taken "inside" the clip. Just above
the stage you should see where you are. It will say Scene1 empty. Meaning
you are in Scene 1 and editing the movie clip called empty.
Now, at this point you need to know the dimensions of the external movie
you are going to load. If you don't, go and note the dimensions...
Right, now while still "inside" the "empty" movie
clip - or inside it's time line, select the rectangle tool and set the
fill to none:

Now draw a rectangle any size. Drag around the whole rectangle - or click
on the stage and press CTRL+A (select all). In the properties - normally
it's already visible by default at the bottom, if not press CTRL+F3 -
set the height and the width the same as the external movie you are going
to load:
Once that's done, and with the whole rectangle still selected, press
CTRL+I. This bring up the info panel:

Make sure that where number 1 is pointing to, the top left square is
black. If not, click it, and where number 2 is pointing to, enter 0 for
x and 0 for y. This is called the registration point. It's where the x
and y of the movie clip are calculated.
Now you should see that the top left of the rectangle you drew has snapped
to the centre of the mc - the cross.:

Now click on Scene1 to get the main time line. Make sure your library
is open - F-11, then drag an instance of the "empty" movie clip
to the stage. Position it where you want. You see the square now represents
the dimensions of the external movie, so you can drag it around and know
exactly where the external movie will load.
Create a button. I will use a pre made one from the Flash library, and
position where you want on stage. Now to load an external movie into the
clip.

On the button put the following code:
on (release) {
_root.empty.loadMovie("external.swf");
}
Now. One thing to remember - make sure that the x and y of the contents
of the external movie are 0. Because the top left corner of the external
movie is aligned to the top left of the empty mc - giving a perfect fit.
See the souce files if you are unsure.
Once you're happy, edit the movie clip and delete the rectangle.
Now how and when you load your external movie is up to you. I've just
shown you an easy way of aligning an empty movie clip to load the external
movie into.
Just for reference - to unload the movie:
_root.empty.unloadMovie();
I have also included an unload button in the source files for this tutorial.
I hope it's been of some benefit.
There is another way of knowing where your external movie will load by
loading into another level - but that will be discussed in the next tutorial.
There is also a way of dynamically creating an empty movie clip with the
createEmptyMovieClip() command - without the need to create an empty movie
clip in the library. |