First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Mindaugas

We're gonna do it simple - no fancy stuff, just basics explained. So, if you need that a flash movie loads another flash movie in the right position - that's covered here.

Where did I needed? I'm designing a 100%-flash site with various types of information. One of the subsections had a few pages of text and some 14 pictures. Now we have a dillema here: if we combine everything under one umbrella, i.e. text and pictures in one swf movie, it's gonna be large (perhaps app. 1MB) - webpage will be laoding slowly. But that's a simple sollution, no headache. A more difficult one: separate the text and pictures into different movies - loading time decreased, since the text loads first (quickly) and a user has an option to check pictures (need to load another swf with pictures after clicking on "pictures" button). The main thing is that an impression of decreased loading time and option to choose is created. But that's a bit more sophisticated. It's done by laoding the swf movie with pictures into the text swf. How to do it right? Step by step answer bellow.

TOOLS USED

loadMovie();
unloadMovie();

- empty movie clip.
- "parent" swf.
- "child" swf.

WHAT DO THEY DO?

loadMovie() - Actionscript command, which loads the movie. Simple. The parameters in the brackets are used to tell 1) which movie to load and 2) where to load it.

unloadMovie() - Actionscrip command, which unloads the movie from cache. Typically, I don't use this command - once user has loaded the movie, it stays in the memory, so if he comes back - the movie will already be in the memory and could be immediatelly played (short - saves time). This command unloads the movie from the cache. You might need to use this command if your "child" movie overlaps with something in your "parent" movie.

empty movie clip - used to define location in the "parent" swf, where the "child" swf is loaded. Does not contain any information in it - it's blank. IMPORTANT - you have to add any instance name (in Flash MX in "Properties" - just type in), which will serve as a link defining location.

- "parent" swf. The movie you're working in, the movie into which you want to load the "child". (Text in my case)

- "child swf. The movie containing information, which you want to load into the "parent" swf. (Pictures in my case)

BACKGROUND TECH INFO

We will use the loadMovie() command to load the child into the parent. However, in flash this command ALWAYS loads the movie in the top left corner (0;0) of an object. If you're working in the Scene1 - that will look ugly, since all your text in "parent" will appear underneath the "child". The trick here is to use the empty movie clip, which calls this command - the movie will be loaded in the top left corner of the movie clip, i.e. in the position, where you have placed that empty movie clip. So, to define the position where the child should load, place the empty movie clip in the desired position in the parent swf. Simple.

HOW-TO STEP BY STEP:

1. Create your child swf, including all external info that you want to load into the parent. For simplicity, let's name it "child.swf".

2. Create your parent swf, including all necessary info. Again, let's name it "parent.swf".

{There are numerous ways to solve this problem. I'm gonna present mine - I just find it more flexible and understanable).

{ALL steps bellow are done in the "parent.fla", except mentioned otherwise.)

3. In the parent movie, create an emtpy movie clip (Ctrl-F8), let's name it "loader". Go back to "Scene 1".

4. On the timeline, insert new layer, let's name it "loading layer". That's the layer, in which the "child" will be loaded. So, check what you need to be visible from "parent", and put that layer in the appropriate position.

5. I use button, which triggers the movie to be loaded. So, insert that button with any text you need in the layer and the place you need it.

6. Click on the button and open "Actions" (F9). Insert the following script:

on (release) {
    gotoAndPlay ("loading child");
}

This script will take you the labeled keyframe "loading child", where the emtpy movie clip is placed and where loading takes place.

7. On the "loading layer" insert a keyframe (F6) at the place, where you want the loading actions to take place. I typically do it at the very end of the "parent" swf, i.e. it would be the last keyframe.

8. Click once on that keyframe on the timeline. In the "Properties" label it "loading child", i.e. just type in those words, where it says "frame label" (bottom left).

9. Insert the emtpy movie clip in that keyframe (just drag from the library). Place it at the position on the screen where you want the "child" to load.

10. Select the movie clip (the one on the screen). In the "Properties", type in the instance name (on the bottom left). Let's say "loading_position".

11. Select the keyframe you're working in (the one labeled "loading child". Open "Actions" (F9). Insert the following script for this frame:

loadMovie("child.swf", "load_position");
stop();

The first line loads the movie "child.swf" where the empty movie clip is placed (remember: it's instance name is "load_position"!). The second line stops the "parent" movie on that location - I use it to control the movie flow. Basically, you need it in order to see the "child" movie.

12. That's it. While working in the "parent" movie, test it (Ctrl-Enter) - should be fine.

You may also want to unload the "child" movie after viewing it if it's blocking what you see in the "parent". Simply use the unloadMovie() command in the parent.

Hope you find it useful. And I do hope I made easy to grasp. Shame on me if not - took more than an hour to type that all.

» Level Intermediate

Added: 2003-09-21
Rating: 6.94 Votes: 95
(10 being the highest)
» Author
ehm... still doing my first steps in flash. but already figured out a few bits.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.