What code to place in a movie to detect if it has been loaded into a movieclip?

Could anyone tell me, please, what Actionscript to put in a movie to detect whether that movie has been loaded into another movieclip?

In case that isn’t clear: movie A loads movie B into a myMovieClip. What code can I put in movie B to detect that it is now a child of myMovieClip, or indeed any movie?

Thanks

loadClip() tells you when it has loaded…

its the best way to load stuff

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002541.html

I’m already using loadClip() to load the movies. What I need to do is place some code in the movies that I’m loading, that will detect if the movies have been loaded by another clip, i.e. they are nested inside another movie.

Apologies if I’m not being clear, or have misunderstood your answer.

you could have arrays which record what you have loaded and where…

the refer to them

check out searching array tuts on main page

Really? Is that the only way to do it?

Is there no way that you can put code on a movie’s main timeline that look to see if that timeline is on Level 0?

Do you mean like:

var root:MovieClip = this;
function hasParent(target:MovieClip):Boolean {
	return Boolean(target._parent && target._parent != root);
}
function hasChild(parent:MovieClip, child:String):Boolean {
	return Boolean(parent[child]);
}
trace(hasParent(root));
// false - root has no parent
trace(hasParent(myMC));
// false - myMC has no parent (except for the root; main timeline)
trace(hasParent(myMC.child));
// true - myMC.child has a parent
trace(hasChild(root, "myMC"));
// true - myMC is a child of root
trace(hasChild(myMC, "root"));
// false - root is not a child of myMC
trace(hasChild(myMC, "child"));
// true - child is a child of myMC

or like myMC.onLoadInit or what :x

That looks like it might do the job. Thanks, I’ll give it a go.

In Movie B you can check to see if _root == your main timeline. This will be false if the movie is loaded in and _lockroot isn’t used. If _lockroot is used, check to see if _root (your main timeline) has a valid _parent value. If so, it’s been loaded into another movie. If dealing with levels, compare against _level0 - this is the value of _root/main timeline for the initial SWF. Other SWFs are loaded in separate levels like _level1, _level2, etc.

i agree with the method senocular suggests…

put such a code in your swf:

ref=this;

now do:

this.onEnterFrame=function()
{
if(_root != ref)
{
delete this.onEnterFrame;
trace(“this movie has been loaded into some other movie”);
}
}

mine does that… in that root is a variable; which, when the code is placed on the main timeline, will return the uppermost level of the SWF; I don’t really see any issues arising, maybe you could tell me any potential flaws?

Wouldn’t the fact that any code is executing be an indicator that the movie has been loaded . . .

I think he wants to know if the movie clip has a parent; ie its loaded into a movieclip

Yeah, but unless it is the root movie it has to have a parent. Therefore testing to see if it has a parent is redundant.

yeah… but its what the man wants :x

He bascally wants to know at a given time … if the swf is its own parent or some other swf is its parent… that way he can know if the swf is playing by itself or within another clip.

Thanks for all your replies!

Just to clarify…

I have a number of different games, all separate fla files, which load into a ‘shell’ movie. The games call a number of functions from the shell movie, so that if their behaviours need to be changed, I only need to change the function. However, when I test the games, for the sake of expediency I don’t always want to load them into the shell movie. The problem that arises, of course, is that testing them independently means they won;t be able to call the functions in the shell movie… so, I want to put a condition in the Actionscript that if the movie has been loaded, it should call the functions, but if it’s running on its own, it shouldn’t.

I hope that makes sense, and that I’ve gone about addressing the issue in the best way. Please let me know if not! And thanks again everyone for your contributions.

pretty much, if the loaded SWF’s main timeline has a parent (*if (this._parent) {} *on the frame) it would be loaded into another MC