# Checking to see if a movieclip exists

**URL:** https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437
**Category:** flash
**Created:** [May 15, 2008, 4:27pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437 "2008-05-15T16:27:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Aubreyff](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Aubreyff](https://forum.kirupa.com/u/Aubreyff)
#### Post date: [May 15, 2008, 4:27pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/1 "2008-05-15T16:27:08Z")

</div>

I have a series of swfs that I am loading externally. Some swfs have a movie clip named ‘DownloadMC’. I am trying to check if the movie clip exists, but I keep getting an error.

```auto

var theMC= MyLoadedMC.getChildAt(timesLoadCalled);// theMC is a loader object so use MovieClip(theMC.content)
trace('it exsists because here is the name: '+MovieClip(theMC.content).DownloadMC.name);//traces 'DownloadMC'
         if(MovieClip(theMC.content).getChildByName('DownloadMC') != null){ var CallTopic:Sprite = new Sprite();
         CallTopic.name = "CallTopic";
         CallTopic.graphics.beginFill(0xFF2200,1);
         CallTopic.graphics.drawRect(MovieClip(theMC.content).DownloadMC.x, MovieClip(theMC.content).DownloadMC.y, MovieClip(theMC.content).DownloadMC.width,MovieClip(theMC.content).DownloadMC.height);
         MovieClip(theMC.content).addChild(CallTopic);
         }

```

the code above gives me an error in the output:

```auto

TypeError: Error #1010: A term is undefined and has no properties.
   at MethodInfo-464()

```

I hope this can be done,  
thanks

Aubrey

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [May 15, 2008, 4:41pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/2 "2008-05-15T16:41:56Z")

</div>

Does CallTopic is instantiated somewhere?

---

<div class="post-metadata">

### Author: ![Aubreyff](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Aubreyff](https://forum.kirupa.com/u/Aubreyff)
#### Post date: [May 15, 2008, 5:52pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/3 "2008-05-15T17:52:50Z")

</div>

yes,

var CallTopic:Sprite = new Sprite();  
MovieClip(theMC.content).addChild(CallTopic);  
CallTopic.name = “CallTopic”;  
CallTopic.graphics.beginFill(0xFF2200,1);  
CallTopic.graphics.drawRect(MovieClip(theMC.content).DownloadMC.x, MovieClip(theMC.content).DownloadMC.y, MovieClip(theMC.content).DownloadMC.width,MovieClip(theMC.content).DownloadMC.height);  
MovieClip(theMC.content).addChild(CallTopic);

but CallTopic is not the problem. I am trying to determine if ‘DownloadMC’ exists in ‘theMC’.

thanks

---

<div class="post-metadata">

### Author: ![Aubreyff](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Aubreyff](https://forum.kirupa.com/u/Aubreyff)
#### Post date: [May 15, 2008, 5:56pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/4 "2008-05-15T17:56:12Z")

</div>

I should say that the code works if ‘DownloadMC’ exists in the loaded movieclip, but if ‘DownloadMC’ does not exist in the loaded movieclip, then I get the error:

TypeError: Error #1010: A term is undefined and has no properties.  
at MethodInfo-464()

---

<div class="post-metadata">

### Author: ![Aubreyff](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@Aubreyff](https://forum.kirupa.com/u/Aubreyff)
#### Post date: [May 15, 2008, 7:42pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/5 "2008-05-15T19:42:49Z")

</div>

I don’t see why you shouldn’t be able to do it the other way, but I got it to work this way.

```auto

for (var childNumber:uint=0; childNumber<MovieClip(theMC.content).numChildren; childNumber++) {
                
                if(MovieClip(theMC.content).getChildAt(childNumber).name == 'DownloadMC'){//works
                    trace(childNumber+' yes it exsists - DownloadMC');
                    var CallTopic:Sprite = new Sprite();
                    CallTopic.name = "CallTopic";
                    CallTopic.graphics.beginFill(0xFF2200,.2);
                    CallTopic.graphics.drawRect(MovieClip(theMC.content).DownloadMC.x, MovieClip(theMC.content).DownloadMC.y, MovieClip(theMC.content).DownloadMC.width,MovieClip(theMC.content).DownloadMC.height);
                    MovieClip(theMC.content).addChild(CallTopic);
                    CallTopic.addEventListener(MouseEvent.MOUSE_DOWN,onTopicMD);
                }else{
                    trace(childNumber);
                }
            }

```

If anyone can explain to me why this

```auto
MovieClip(theMC.content).getChildByName('DownloadMC')

```

gives me an error when the object doesn’t exist? is their a way to return a boolean?

---

<div class="post-metadata">

### Author: ![xohol](https://avatars.discourse-cdn.com/v4/letter/x/59ef9b/32.png) [@xohol](https://forum.kirupa.com/u/xohol)
#### Post date: [May 15, 2008, 8:50pm UTC](https://forum.kirupa.com/t/checking-to-see-if-a-movieclip-exists/260437/6 "2008-05-15T20:50:27Z")

</div>

you could count the children of the parent clip. if numChildren \> a set amount, you should know that the DownloadMC clip is there.
