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 Wild FX (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 Wild FX, 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.
The Stage and Timeline
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. Either double-click
the empty movie clip, or single-click
it and hit CTRL-I to bring up the Instance
Properties dialog box. Enter a name;
I have used "empty" for simplicity.
Instance Properties Dialog Box --
Empty Movie Clip
In
the first frame, there is a Load Movie
command. To do this, double-click the empty
keyframe in the timeline. This brings up
the Instance Properties dialog box. Click
the "+" button to bring up a list of commands.
Select "Load Movie" and fill it out as
I have done, specifying the SWF to load
and the target ("../empty" means the movie
clip "empty" one level up).
Stop Action 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 create a button, draw whatever you want
on the stage. Select that object, and hit
F8. In the dialog box that pops up, enter
a library name for your button and be sure
to select "Button" under behavior. Then,
return to your main timeline (CTRL-E) and
your button is where you left it on the
stage.
To add the Load Movie action to a button,
double-click the button, bringing up the
Instance Properties dialog box. Select
the "Actions" tab. Click the "+" to choose
a command and select "On MouseEvent". In
the pane, you must choose from the list
of mouse events; I have chosen On Release,
meaning that this action is executed on
mouse up (the command is executed as the
mouse button comes up, just like HTML links).
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. To add a
label to a frame, double click the desired
keyframe on the timeline, bringing up the
Instance Properties dialog box. Select
the "Label" tab and enter a name.
At
the frame labeled, "unload", the button
text changes to "Unload" and the button
itself now has an "Unload Movie Clip" command.
The Unload Movie command is directly beneath
the Load Movie command in the "+" actions
list. All you have to do is enter the target
(the movie clip into which you initially
loaded your SWF). Click the "Unload" button
in the SWF, and you will notice the animation
disappear. At this point, the movie returns
to the frame labeled "load", where we began.
Button
Action -- Load Multiple SWFs into Multiple
Movie Clips
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 (you do
not need to create 6 separate movie clips
in your library - instead, just create
one empty movie clip in your library and
drag it onto the stage six times, thus
creating six instances), with 6 different
instance names ("empty1", "empty2" … "empty6").
Instance Properties Dialog Box --
Empty Movie Clip
This sample is basically six copies of
the previous example all in the same SWF.
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.
Instance Properties Dialog Box --
Load Movie Command
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 on the stage
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 simple, single-frame
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.
Please note that 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 is 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?
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.
Bring up the Instance Properties dialog
box (by double-clicking the button) and
select "Set Property". On the right side
of the dialog box, select "Visibility" for "Set:".
Then, enter your target (here, "../empty_holder/empty")
and then choose a value (for the visibility
property in Flash, 0 means invisible and
1 means 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 five
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.
To create a motion tween, create all your
keyframes, select them (you can also apply
a motion tween to a single keyframe) on
the timeline with your mouse, right click,
and choose "Create Motion Tween".
empty_holder Movie Clip Timeline and
Stage
With this timeline constructed, building
the "fade" and "move" buttons was quite
easy. Using the "Tell Target" 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 at frame 1.
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.