Dynamiclly loaded .swf files

Hello All!

I created a flash web site where I’m dynamically loading all the .swf files into one. I’m using Flash 8, Actionscript 2, Flash Player 8. The goal was to break up the file size of the project and load the .swf files via four buttons ‘HOME’ ‘PEOPLE’ ‘RESEARCH’ ‘PUBLICATIONS’ repectively. I was able to do this using the following code for the buttons.

button_name.onRelease = function () {
createEmptyMovieClip(“container”, 1);
loadMovie(“people.swf”, “container”);
container._x = 0;
container._y = 0;
}

This works great but now it seems like all the .swf files are all loaded into the same file and the flash page runs slower when going from one to the next. I can tell they are still there bc the buttons in the ‘PEOPLE’ .swf are active when I hover over there X, Y position.

Anyone have any idea how I can alleviate this problem? I would assume that I need some kind of ‘if’ statement that deletes the previous .swf file that was loaded, but, I am unable to wrap my brain around the logic.

The hiearchy of the flash site is as follows

-HOME PAGE:
Loads the home page movie clip and image with buttons at the top for navigation. The buttons are ‘HOME’ ‘PEOPLE’ ‘RESEARCH’ ‘PUBLICATIONS’

Click on ‘PEOPLE’ loads ‘people.swf’
Click on ‘RESEARCH’ loads ‘research.swf’ within research.swf there are a series of buttons that load other .swf files dynamically.

Any help will be greatly appreciated.

-Atris

Is the code on each button the same?

Instead of creating a new loader clip every time why not create an empty movieclip, give it an instance name (like container) and stick it where you want it on your main stage (assuming every button loads content into the same location). Then on the button you only need to include the loadMovie command (and you won’t have to worry about levels). By loading into the same container the next swf will replace the previous swf and you don’t have to worry about unloading it or worry about button still being there, etc.

:hr:

yes that sounds like a good idea. so the code on the actions layer should be

function name () {
_parent.createEmptyMovieClip (“container”, 1);
container._x = 0;
container._y = 0;
}

then on the button

on(release){
loadMovie(“name.swf”, “container”);
}
not sure how to code the button, but i feel like i’m almost there!

BTW, love the pic

Sort of. You don’t have to dynamically create the empty movieclip. Go to the Insert menu --> new symbol --> and choose movieclip. Make sure you give it an instance name. Stick it where you want it on the stage (knowing that external objects always load their upper left corner at the registration point of a movie clip).

Then yes on your button just use

//assuming button symbol
on(release){
loadMovie("name.swf", "container");}

If you are using a movieclip symbol for your button the code will be slightly different and won’t go on the button itself, but sounds like you know how that works. :slight_smile:

Also you should know that you can’t dynamically change an empty movie clip’s properties (e.g. size, scale, or x/y position). You have to wait until the external object is fully loaded - then you can change it. Many people use preloader code to see if the external has been fully loaded, then initiate code to change the property.

:hr:

edit also, if you are using MX then the code on the button would be

_root.container.loadMovie("name.swf");

for some reason MX2004 likes to have loadMovie(“name.swf”, “container”) but I’m not sure why the difference.

It works but still seems to be loading the same. All the .swf files still seem to be there instead of being deleted. I can still hover over the button instances in the people.swf file from the main swf file

What to do what to do?

Still calm but slowly losing it :wink:

are you loading into different containers?

no, same movie clip called container.

two buttons called
btn_peeps
btn_research

code on each button

on(release){
loadMovie(“people.swf”, “container”);
}

on(release){
loadMovie(“research.swf”, “container”);
}

One thing I just thought of is that i’m loading the home page movie clip then with the buttons i’m loading the other movie clips…could that be the problem?

Hard to know without seeing how you have this set up.

If you are using MX or MX04 can you post your main fla and the external swfs? I don’t have Flash 8 though.

That’s cool, I’m going to try to see if I can get it worked out. You’re right though it might be something with the way i have it set up.

I really appreciate the help.

I’ll see you around.

Atris