loadMovie Question

hello all,
i want to import a swf-file into my flashfile. i wrote the actionscript loadMovieNum(“mymovie.swf”, 10), but the movie is at the wrong place! how can i place the movie at a specific postition? can someone guide me? i am a newbie to flash and actionscript.
regards,
momo

you can load it into a movieclip, and then you can place that movieclip where ever you want… you’ll need to do it this way tho:


loadMovie("myFile.swf", _root.target)

where _root.target is the path to your movieclip

cheers
:A+:

if you have any type of _root referencing code in your loaded movie it will be broken when loaded into a movieclip of another movie. The reason for this is that the _root is actually shifted to the _root of the main movie and not the scope of its original _root which is now the clip it was loaded into.

You can move _levels but you have to wait until they are fully loaded before being able to do so. This may take a few frames/seconds depending on the size of your movie. you can set up a frame loop to check for if(_level10) to see if the level ‘exists’ before moving it or simply wait until its loaded comparing getbytesloaded/total. and moving on completion.

If you dont have to worry about script breaking, ahmed’s suggestion would most likely be the best though ‘target’ is a keyword in flash and a new name for the movieclip might be preferable

thanks for your fast reply,
but HOW can i place it whereever i want? which is the function for that?
i tried the code you provided, but now i only see the movieclip i imported (the background of my movieclip i can´t see anymore).
i am new to actionscript, so please excuse my beginnerquestions…
regards, milena

to position a movieclip where ever you want on the screen you alter that movieclip’s _x and _y properties. These properties reference its x and y position on the screen. Setting _x to 100 and _y to 200 would put a movieclip in the position (100,200) or 100 pixels from the left and 200 pixels from the top (the _x starts at the left with a value of 0 getting progressively larger as you move right while _y starts at the top getting progressively larget as you go down).

if you have a movieclip on the screen with an instance name “box” you can move it to the position of (100,100) by saying

box._x = 100;
box._y = 100;

No problem right? Chances are you might have already known this. If not, you do now. So we can see the form is

ObjectName.property = newValue

Now, when you load new swfs into an existing swf, you have 2 options. You can 1) load it into a “level” in flash which is basically throwing the entire new flash movie on top of the existing one or you can 2) load the swf into a movieclip within the current movieclip. This method transforms the swf into that movieclip and makes it a part of the original movie.

Lets start with 2…
What youd need first is your main movie. Seems like you already have one. Great. Now you need to make a movieclip to load your other swf into. You can make this any size you want or no size at all. Its common to use the latter, just making a completely empty movieclip. When placed on the screen it will appear as a black of white circle. Once there, you can movie it and place it where ever you want. This will be the position of the upper left corner of whatever movie you load this into. Remember how _x starts at the left and _y starts at the top? These starting positions are the 0,0 points or the origin (or registration point) of the movie - effectively the center of your movie. For any movie you make in flash, the “center” point is actually in the upper left of the movie. If you ever resize your movie you’ll notice how it always goes right and down, this is because its all based of that upper left “center”. Because this is the center, its this point which is positioned on the actual center of the clip youre eventually loading it into when loading into a movieclip.

So lets assume your new empty movieclip you made which you plan to load a swf into is called box and placed on the main timeline. Position where ever you want on the screen then add the action

loadMovie(“loadedMovie.swf”, _root.box);

to load your external swf into it (this can be on the timeline or on a button or whereever you need it to be). Since you positioned it manually in Flash, this new loaded movie will now be in that location. If you ever need to move it further from that point on, just use

box._x = newXLocation
box._y = newYLocation

Now for 1…
Using levels. Loaded swfs are probably more usually loaded into levels, especially when they are more standalone functional swfs which need to be included in an already present movie. Typically, if you know your movie is going to be loaded into a main movie, you will position it accordingly within its own screen so it will fit right when loaded. If not, then you have the option of moving it once its loaded into a new level in the original main movie. Levels are loaded using loadMovieNum:

loadMovieNum("“loadedMovie.swf”, 1);

where 1 represents the level of the loaded clip. As I said before, levels are the movies completely intact just thrown on top of the original. They will work just as they would if loaded alone (unless you mess with _levels in there). when ever a level is loaded into a movie its placed at the 0,0 point of that movie, which as you should know is the upper left. This puts it flush left and top of the main movie. You are able to move levels as you are movieclips, but before you can, a level has to exist first. A level exists only after a movie (or at least a substantial amount of a movie) has been loaded into that level. Here is where the problem comes. Because you have to wait until the level is atleast somewhat loaded, you cannot position it directly after the loadMovieNum call. Instead you’ll have to wait. Here is where the frame loop and the check of if(_level) comes into play. There are 2 different ways to do this, either through a frame loop on the timeline or from within an enterFrame event of a movieclip. Both have the general idea.


// movieclip event
onClipEvent(enterFrame){
	if (_level1 && !_level1.isLoaded){
		_level1._x = 100;
		_level1._y = 200;
		_level1.isLoaded = true;
	}
}

// frame event (frame 2 or greater
if (_level1 && !_level1.isLoaded){
	_level1._x = 100;
	_level1._y = 200;
	_level1.isLoaded = true;
	nextframe();
}else{
	gotoAndPlay(_currentFrame-1);
}

An extra variable isLoaded was thrown in so we know not to repeat the positioning every frame while the movie has been loaded which is just un-needed and would ruin any kind of re-positioning you might try to do further down the line since this would always bring it back to this set location. This example uses level 1 and when it sees level 1 as being existant and sees that its isLoaded is not true, then it repositions it and sets isLoaded to true. In the frame example, it loops from the frame this is on to the current frame and continues that loop until loaded where the playhead is moved and stopped on the next frame.

Obviously the first example (#2) using movieclips to load your movie into is a bit easier but sometimes you need to maintain your loaded movies functionality and steps such as those above need to be taken. Still, its generally the ideal to position these clips within the movie itself and not move the levels at all.

senocular I have tried what you explained…The naming the empty movie clip as box did work…but only on certain swf’s i had

i want to put a navagation bar at the bottom of my page and it does not come up :frowning:

yet i try a different swf and it works perfectly =X

here let me show you…here’s the FLA

http://www.liquidmixer.com/testing/site%20test.fla

I know the swf works by itself ----> http://www.liquidmixer.com/testing/testing.swf

Edit: I’m using FlashMX btw =)

I think youve run into the problem of the script not working because of it referencing _root which was the reason youd need to load into a level instead of a movieclip. I cant tell for sure because I dont know the script of testing.swf but it works when loaded in a level just fine

You can either go in and change the script not to use _root, or use a level instead

so you would suggest loading it into a level?

where do I put that as that you posted…do i put it on the main time line or do i do it on the movie clip

errr…im not sure if im being clear

either right clicking on the timeline and selecting actions…or right clicking on the movie clip and selecting actions?

sorry for my nooB questions…but I tried it and it said it had some errors :*(

I would just include it in the original since it is a menu. It seems like a needed asset.

But otherwise, Id re-write it to work in a movieclip. Moving levels is a pain compared to pre-positioned movieclips.

*Originally posted by senocular *
**I would just include it in the original since it is a menu. It seems like a needed asset.

But otherwise, Id re-write it to work in a movieclip. Moving levels is a pain compared to pre-positioned movieclips. **
hmmm…

what i want to do is something like on this site

www.mixinmarc.com

you see how the navagation is always on top…and the pages just load to the back :beam:

is there a way to do this if its in the original…(im trying to keep the file size low…so I want to only load what is necessary)

Hi senocular and openmind,
I’m having some problem with this

Senocular u say in option 2

So lets assume your new empty movieclip you made which you plan to load a swf into is called box and placed on the main timeline. Position where ever you want on the screen then add the action
loadMovie(“loadedMovie.swf”, _root.box);
to load your external swf into it (this can be on the timeline or on a button or whereever you need it to be). Since you positioned it manually in Flash, this new loaded movie will now be in that location. If you ever need to move it further from that point on, just use
box._x = newXLocation
box._y = newYLocation

well… i’ve done just that, created an empty movie clip holder, positioned it at say 100,200 - exactly where i want the movie displayed - so i don’t need to change _x and _y of the holder. However the movie i load into the holder seems to load into the bottom quater of the holder - that’s not where I want it to be but aligned with the top left of the holder. what do i need to do here ?

Openmind u say -

As far as I know when you load a SWF or image file into a movie clip target, the upper-left corner of the SWF file or image is placed on the registration point of the movie clip. Because this registration point is often the center of the movie clip, the loaded content might not appear centered.

now the registration point of my movie clip holder is set to the top left. why then is the upper left corner of the SWF movie not being placed on the registration point of the holder ?

btw in the swf file my images are placed at 0,0
also the holder is able to load and align properly movies in the library itself with the attachMovie cmd. Its the loadMovie that I’m having problems with

pls any ideas anyone?

-Mamta