Checking to see if a movieclip exists

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.


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:


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


I hope this can be done,
thanks

Aubrey

Does CallTopic is instantiated somewhere?

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

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()

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


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

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

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

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