| Now position your content mc
so that it is centered vertically and over
the right hand side of the stage.
Save your movie as main.fla into a folder
called "how to use loadMovie".
Now make a new file. Set its stage size
to 250 wide by 300 high (the same size
as our content mc) but don't worry about
the background colour or the frame rate.
When an swf is loaded into another movie,
it takes on the frame rate of the parent
movie and the background becomes invisible.
However, it would probably be best to
set the background colour to the same
dark grey that you used in your main.fla
(this will help for choosing colours
etc..). Type on to the stage the words "I
just got loaded into a target.".
Use Arial, 8pt, white. Make sure it is
set to "static text" and check
the box that says "Use device fonts".
This means that if the user doesn't have
the font that you have specified then
it will default some other font that
they do have installed (usually something
like Arial). This has 2 advantages -
1 - Flash doesn't have to embed the
font in your swf therefore reducing the
file size
2 - Flash does not anti-alias the text
which will improve the clarity of the
type when using a small point size. Test
the movie now and you will see the effect.
There are numerous disadvantages to
using device fonts as well but I won't
go into those now.
Save your new movie as content1.fla
into the same folder as main.fla. Go
into the publish settings for content1.fla
(File/Publish settings) and uncheck the
HTML box so that just the swf box is
checked. Click on the Publish button
then click OK. Go back to main.fla, make
a new actions layer and put this action
in the first frame -
loadMovie ("content1.swf", "_root.content");
Now test your movie.
See what happens? Flash loads in the
external movie and aligns the top left
corner of the stage in your external
movie with the cross hair of your target
clip. You will also notice that when
the external movie loads in it replaces
the box graphic that was inside your
content mc.
Now we can target our loaded movie and
tell it to do whatever we want. Go to
your content1.fla, make a new actions
layer and put a stop action in the first
frame. Create a keyframe in frame 2 of
the actions layer and put a stop action
in there as well. Click on frame 2 of
the layer that has the text on it and
create a keyframe. Change the text in
frame 2 to "you just targeted me
and it felt so good". Publish your
movie (File/Publish). OK now go back
to your main.fla. Name the layer that
has the content clip on it "content" and
create a new layer - name it buttons.
OK click on the first frame of your buttons
layer and draw a small rectangle. Select
the rectangle, convert it to a button
and name it button. Give your new button
an instance name of "button1".
Now place this action on frame 1 of the
actions layer, underneath the loadMovie
action that is already there.
button1.onRelease=function(){
_root.content.gotoAndStop(2);
}
A couple of things to note here. You
will notice that to target our external
movie we just need to target the clip
that it has been loaded into. The action
you see there is actually a much better
way of doing the tellTarget action that
you have all used before (they do the
same thing, it's just that tellTarget
is Flash 4 scripting and can do some
weird and unexpected things sometimes).
I want you all to get in the habit of
using this code rather than tellTarget
- OK?
Test your movie and click on your button.
Back to content1.fla. Save your movie.
Now choose "Save As" and save
it as content2.fla (make sure you save
it to the same folder as the other flas).
OK in the content2.fla, change the text
on frame 1 to "I am content 2 and
I am better than content 1". Change
the text on frame 2 to "something
amusing". Save your movie and then
publish it.
Back to main.fla. Option-drag your button
on the stage to make a copy of it. Change
the instance name of the new button to "button2".
Add this action underneath the rest of
your actions on frame 1 of the actions
layer.
button2.onRelease=function(){
loadMovie ("content2.swf", "_root.content");
}
Test your movie and click on both the
buttons. You will see that the original
button still works and sends whatever
movie is loaded to frame 2. Obviously,
the second button loads the content2.swf
you created which replaces whatever has
been previously loaded into the content
mc.
That's enough for loading into targets I think - experiment with it -
see what happens if you load in movies that are bigger than your target
etc.
|