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

**URL:** <https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887>\
**Category:** flash\
**Created:** [July 14, 2008, 10:16am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887 "2008-07-14T10:16:41Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)\
**Post date:** [July 14, 2008, 10:16am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/1 "2008-07-14T10:16:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [July 14, 2008, 10:22am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/2 "2008-07-14T10:22:22Z")

</div>

**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](http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002541.html)

---

<div class="post-metadata">

**Author:** ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)\
**Post date:** [July 14, 2008, 10:37am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/3 "2008-07-14T10:37:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [July 14, 2008, 11:04am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/4 "2008-07-14T11:04:07Z")

</div>

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

the refer to them

check out searching array tuts on main page

---

<div class="post-metadata">

**Author:** ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)\
**Post date:** [July 14, 2008, 11:11am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/5 "2008-07-14T11:11:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 14, 2008, 12:06pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/6 "2008-07-14T12:06:43Z")

</div>

Do you mean like:

```auto
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

---

<div class="post-metadata">

**Author:** ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)\
**Post date:** [July 14, 2008, 4:02pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/7 "2008-07-14T16:02:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [July 14, 2008, 4:24pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/8 "2008-07-14T16:24:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 14, 2008, 7:54pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/9 "2008-07-14T19:54:34Z")

</div>

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”);  
}  
}

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 15, 2008, 1:38am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/10 "2008-07-15T01:38:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [July 15, 2008, 1:54am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/11 "2008-07-15T01:54:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 15, 2008, 5:49am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/12 "2008-07-15T05:49:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [July 15, 2008, 5:56am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/13 "2008-07-15T05:56:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 15, 2008, 7:29am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/14 "2008-07-15T07:29:08Z")

</div>

yeah… but its what the man wants :x

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 15, 2008, 7:43am UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/15 "2008-07-15T07:43:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)\
**Post date:** [July 15, 2008, 2:07pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/16 "2008-07-15T14:07:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 15, 2008, 2:13pm UTC](https://forum.kirupa.com/t/what-code-to-place-in-a-movie-to-detect-if-it-has-been-loaded-into-a-movieclip/265887/17 "2008-07-15T14:13:21Z")

</div>

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
