removeChild Problem

Hi guys!

So i have this problem that is bugging me a little bit and hopefully, someone could help.

Here’s the code:


package
{
    import flash.events.Event;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
        
    public class ShapeOuts extends MovieClip
    {
        public function grow():void
        {
            var container:empty = new empty();
            var myShape1;
            
            container.x = 240;
            container.y = 64;
            
            addChild(container);

            if(container.contains(myShape1))
            {
                container.removeChild(myShape1);
            }
            
            if(root && Object(parent).ShapeDetect == 1)
            {
                myShape1  = new Shape1L();
                container.addChild(myShape1);
            }
            if(root && Object(parent).ShapeDetect == 2)
            {
                myShape1  = new Shape2L();
                container.addChild(myShape1);
            }
            if(root && Object(parent).ShapeDetect == 3)
            {
                myShape1  = new Shape3L();
                container.addChild(myShape1)
            }
        }
    }
}

what i want here is that if there is an existing child in my container, i want it to be removed. Problem is, im getting this error.
TypeError: Error #2007: Parameter child must be non-null.

Is there any solution to solve this problem?
Thanks in advance