Note: If you are using
a thirty party Flash tool such as Wildform
Wild FX and want to avoid using the
Load Movie command in Macromedia Flash,
try Wildform Linx,
which eliminates the need to use Load Movie
by allowing you to import every kind of
Flash (SWF) file.
Introduction
Load Movie is an essential command to any serious Flash developer, as well
as any user of third-party SWF software such as Wildform Wild
FX, since Macromedia Flash can not import Flash 4 or 5 SWFs. Despite
its importance, however, very little information is available on the Load
Movie command and how to use it.
This tutorial covers the basics of using Load Movie in Flash 5. After reading
it, and studying the attached (simple) FLAs, you will be able to load and
control multiple SWFs, using button or frame actions, with very little
hassle.
There are two types of locations
into which one may load an external SWF --
a level, or an empty movie clip. In general,
I prefer and recommend working with empty
movie clips, as they are more controllable
and agile at design-time (when you are building
your FLA) and at run-time (dynamically, by
ActionScript, when your movie is running).
Loading movies into layers is most useful for loading many, or an undetermined
number of external SWFs, since levels do not need to be created before
loading an SWF into one. To load several SWFs into movie clips requires
the manual placement and naming of the empty movie clips in Flash, or the
use of the Duplicate Movie Clip command (if you are interested in learning
how to use the Duplicate Movie Clip command for this purpose, please view
the Wildform Banner Ad Engine tutorial, which is intended for advanced
Flash developers). But, on the whole, I find loading SWFs into empty movie
clips more reliable and useful, and the examples in this tutorial are based
on that method. That said, however, with the exception of the final example, "Controlling
SWFs Once Loaded", all of these samples could just as well apply to loading
a movie into a layer rather than an empty movie clip - simply replace the
target of the Load and Unload Movie Clip commands with a level number.
Positioning
Your SWF
The most common question concerning
Load Movie concerns the placement of external
SWFs using empty movie clips. The center
point of your empty movie clip in Flash (the
dot on your stage, or the cross-hair when
you edit the movie clip) is where the upper
left corner of your external SWF will be
located. That's it. That's the only rule.
If you get it, you should skip the following
paragraphs, which contain a bit more detailed
explanation.
Perhaps it might be easiest to think of it in these terms. The upper left
corner of the preview window in SWfX (which is the upper left corner of
the SWF you create) is the 0,0 x-y position. So, for example, if you place
your animation at 20, 30 in SWfX, it will begin 20 points from the left
side and 30 points from the top of the preview window.
In Flash, the 0,0 coordinate in your empty movie clip is the cross hair
that appears in the middle of your stage when you edit the movie clip.
So, an object that appears at (20,30) would appear 20 points to the right
and 30 points below the cross hair.
So, to align your movies, all you have to do is align your (0,0) points
- the center-point of your empty movie clip and the upper-left corner of
your SWF.
In this movie, the SWF is loaded
and nothing else happens. This FLA for this
SWF is very simple. There is one timeline,
with two frames. An empty movie clip is on
both frames. To create an empty movie clip,
view the Library (CTRL-L if it is not currently
visible). On the upper right of the window,
select "Options" and "New Symbol". Give it
whatever name you wish, and be sure to select "Movie
Clip" under behavior. Do not do anything
else with this movie clip.
Then, return to your main timeline (CTRL-E if it is not currently visible)
and drag the new movie clip from the library onto your stage (see "Positioning" above
for proper placement of your movie clip). Now you need to name this instance
of your movie clip. Make sure the movie clip is still selected, view the
Instance Properties panel (CTRL-I if it is not currently visible) and enter
a name. I have used "empty" for simplicity.
In the first frame, there is a Load Movie command.To
do this, select the frame in the timeline, and then view the Actions window
(Window -> Actions, or CTRL-ALT-A). Then, under basic actions select Load
Movie. At the bottom of the actions panel, enter the URL you wish to load,
and the target (in this case, the movie clip "empty").
Then, the second frame contains a stop command. Please note that the stop
command can not immediately follow the Load Movie command on the same frame,
because such code would fail to load the external SWF.
Button
Action -- Simple
Taking this previous example
one step further, let us apply the Load Movie
command to a button, so we can choose when
to load the animation. So, in this example,
the movie waits until the user clicks the
Load button to load the animation.
To add the Load Movie action to a button, select the button and view the
Actions window. Under "Basic
Actions", select "On MouseEvent". I have chosen On Release, meaning that
this action is executed on mouse up. Then, select the Load Movie command
in the same Basic Actions list and fill in the appropriate information
at the bottom of the Actions window.
Once
the user clicks the "Load" button, the Flash player runs the Load
Movie command and then proceeds to the frame "unload" as indicated
by the ActionScript. Now, the button changes to "Unload" and now
has an "Unload Movie Clip" command. The Unload Movie command is
directly beneath the Load Movie command in the Basic Actions list.
All you have to do is enter the target. Click the "Unload" button
in the SWF, and you will notice the animation disappear.
Building directly on top of the previous example, let's say that we have
six different movies to load. And, we need to be able to view all six simultaneously. This
means that we need to create 6 copies of that "load/unload" button and
6 empty movie clip instances (just drag the movie clip from the library
on to your stage six times - you do not need to create 6 separate movie
clips in your library), with 6 different instance names ("empty1", "empty2",
etc). Each load button loads an animation into the corresponding empty
movie clip. And, as in the previous example, when the "load" button is
clicked, it becomes an "unload" button, which empties the appropriate movie
clip and returns the button to its default "load" state.
Button
Action -- Load Multiple SWFs into One Movie
Clip
Now, as with the previous example,
let's assume that you need to load several
external SWFs - but this time no more than
one needs to be visible at once. This fact
is important because, unlike in the previous
example, here we need only one empty movie
clip instance since all the animations one
can be loaded into the same movie clip.
Each load button differs from the others in the name of the file that it
loads - however,
the target movie clip specified in the Load Movie command on each button
is identical (labeled "empty"). The "Load" buttons in this sample are just
load buttons - not two-frame "Load/Unload" buttons as in the previous two
samples. To unload whichever animation is currently loaded, click the "unload" button
at the bottom of the SWF.
When you load an SWF into an empty movie clip, any SWF that might already
have been loaded into that location is automatically purged, or unloaded,
from the SWF. For example, if you click "Load 1", the first animation appears.
If you click "unload", the first animation disappears. If you then click "Load
2", the second animation appears. Now, instead of clicking "unload" before
clicking "Load 3", you just click "Load 3". You will notice that the second
animation disappears and is replaced by the third animation - there was
no separate Unload Movie command necessary.
Now that you've learned how
to load single and multiple movies into single
and multiple locations, what do you do with
them once they are loaded? You can do anything
that you can do to movie clips in Flash.
As you increase your grasp of ActionScript,
you will realize the possibilities of working
with and manipulating movie clips.
As a simple demonstration, I have prepared three separate actions - the
three most common questions that we receive regarding manipulating loaded
SWFs: fade, move and hide.
The
actions on these buttons are quite simple. I will start with "hide",
since that is by far the easiest command of the three. As you can
see, it's a simple SetProperty command. As with the buttons in
the previous sample, this button action is triggered On Release.
Then, under the "Actions" list (directly beneath "Basic Actions"),
choose "setProperty" and fill out the command to read setProperty
("_root.empty_holder.empty", _visible, "0");. To return visibility,
simply click show, which issues almost the identical command, with
the "0" (which means invisible), with a "1" (meaning visible).
While it is possible to move and fade movie clips with ActionScript (by
shifting the _alpha, _x, and _y properties for the movie clip), that is
not the easiest method, and it is not the method I have chosen to illustrate
here. You will notice that in this example, I have placed the empty movie
clip within another movie clip, labeled "empty_holder". The timeline for "empty_holder" contains
66 frames. There is an instance of "empty" on the stage in all of these
66 frames. There are three labels in the actions layer of this timeline:
normal, fade_out, and move.
At normal, "empty" is in its proper location at 100% alpha, and there is
a stop action. At "fade_out", "empty" is also in the right place at 100%
alpha. From here, the timeline plays to frame 19, where "empty" is at 0%
alpha, where the motion tween (the animation) stops. The timeline continues
animating until frame 28, when it is told to return to "normal" and stop.
At "move_out", "empty" is in the right place at 100% alpha. Then, over
the next 16 frames, there are 6 keyframes, with "empty" in various positions.
The motion tween creates the animation, rather than sudden jumps. The timeline
continues playing until frame 66, when it is told to return to "normal" and
stop.
With
this timeline constructed, building the "fade" and "move" buttons
was quite easy. Using the "With" command, clicking
the fade button tells the "empty_holder" movie clip to go to the
frame labeled "fade_out" and play. And clicking the move button
instructs the "empty_holder" to go to the frame labeled "move" and
play. Both of these result in the desired animation, at the conclusion
of which "empty_holder" returns to its normal, default state.
Since the buttons are active at all times, they can interfere with each
other. For example, clicking "move" when the clip is in the middle of fading,
will make "empty_holder" jump to "move_out" - thus immediately returning
to 100% alpha.
Wildform
provides a 100% satisfaction guarantee on all our Flash software.
If you are not completely satisfied with our Flash multimedia software
for any reason you may request a refund within 15 days
of purchase.