In this module we are going to be learning a technique that allows you to build larger media-rich projects, by dividing your project in different parts (different “swf” files), and using a Main Movie containing the General interface as a host or home-base.
We call this: Loading an external movie (swf) into your movie.

This technique allows you to begin with a relatively small movie that loads quickly over the internet, and then load other content WHEN the user asks for it, and only IF they do ask for it.
(if they push the button that triggers the process).
This is called dynamic loading, or loading on demand.

Newly loaded movies show on your web page/app like any other content inside the Main movie, so the user doesn't really detect that something out of the ordinary has happened;

The other external movies live in the server in the SAME folder where the main swf and corresponding html page are stored.
You also need to keep them all in the same local folder in your computer.

You can read about this techniques and the action Scripting that makes it work in your book.
Look at Chapter 9, pages 312 to 315, Loading External content.

Notice that there is also code for removing an already loaded movie (page 316). Since we will be loading at different points in the Timeline we will not need that code.You will see it in place in the second smaple file (with Lading and unloading).

In AS3 there are 2 different ways of loading external material to a flash movie, and those are:

_Loading it straight ahead to the Stage(The main Timeline).

_Loading the external movie INSIDE a LOCAL movie-clip symbol (as a child object_ AS3 term).
The benefit of this second technique is that the location of the local movie (both as a layer level and as a position on the Stage area) defines the location of the external movie once loaded. You can also scale, tint, or skew the host movie and the child movie will inherit those properties.

Another benefit is that the "local movie-clip" acting as a host, automatically looses the previous content every time that you load a new external movie inside, so you don't have to create scripts to unload previous content showing up on the Stage.

 

When swf movies get loaded into the Stage, the movie appears aligned to the origin coordinates of the main project, and that is the upper-left corner of the Stage (the x=0, y=0 point).

In my sample file we are loading the external movies into a movieclip called place_mc and located on the Stage.
The coordinates of the loaded swf is the same than those of place_mc.
This is how you calculate the position.
You avoid this way of having to redesign or save space of main navigation on every external movie.

The new loaded content will appear to the right and down of the host's center (the movieclip little cross mark).
Most of us place things inside a movieclip using the cross as a center, so beware of this change.
Just think of the content using the cross as the upper most left point.

Content rightly aligned INSIDE the movieclip

My video-tutorial with general guidelines for the main interface and how to organize the external swfs.
You can use the same code to load external images (jpegs, gifs).
Notice that this movie is 24 minutes long.
http://soma.sbcc.edu/users/ajarabo/F_online/A_MOODLE_FILES/Training_movies/Loading_external1.mov

There is a tutorial in your help site. You can see the structure of the flash movies for this assignment.
It is a 2 page tutorial using the same material that you get in the sample file:

http://soma.sbcc.edu/users/Ajarabo/F_online/loading_externalM.htm

 

 

Remember that to build the code to load an external swf movie, you need to know:

1. The exact name of the external swf. You will have to write it down in the script.
The external movie (swf file) needs to be located in the same folder than your main movie.
This is true when you test the movies in your local computer AND when you copy them to the server.

2. The instance name of the local movieclip.
The local movieclip NEEDS to be Placed on the Stage and have an assigned name (through the Properties Panel).

3. The position of the external movie on Stage depends on the position of the local host movie.
It would be a good idea to draw a rectangle of the same dimentions that your external movie inside the host, and align it to the upper-left corner of the symbol, to preview the result.
The center of the symbol is the little cross that you see in the middle.
The rectangle should be positioned with the little CROSS placed on the upper-left corner of your content!

4. It is important to know that external movies DON'T carry their background color into the main movie.
Think of them as "movies with a transparent background".

5. It is also important to keep in mind that external movies don't take their Stage dimension with them: Everything will be visible when they get loaded into the main movie,
all content placed in the paste-board area.
This is important if you are using pans along the stage or animations that involve elements out of the stage at a certain point.

To have your external movie looking exactly the same when you play it inside the mother flash, build a mask the size of the Stage and put all the layers under the effect of the mask.

 

The code to load an external file

 

The code in As3 to load an external file entails 4 parts:

 


1
. Loader object

 

declare
variable
  name of your variable   semi
colon
  data type   equal   make a new
loader
 
var
myLoader
:
Loader
=   new Loader();  
 


2
. URL Request object

 

declare
variable
  name of your variable   semi
colon
  data type   equal   make a new
loader
    name or your swf in quotes  
var
myURL
:
URLRequest
=
new URLRequest
(
"external.swf"
)
 


3
. LoadURL Request inside
the loader

 

variable for loader   dot   action of loading       variable for URL request      
myLoader
Load
(
myURL
)
 


4
. Place the loaded movie

in your project

 

On Stage
  Place new external movie            
addChild
(
myLoader
)

 

Inside a movieclip host
  name of movieclip on Stage dot Place new external movie            
place_mc
addChild
(
myLoader
)