Can't addChild after deleting it (Error #1009)

Hello, I’m trying to delete and create new movieclip but I’m getting errors. Here’s my code:

function onNumericStChange(event:Event):void {
    subunits = event.target.value;
    isEditSet = false;
    
    container.parent.removeChild(container);
    
    if(container.parent) {
        container.parent.removeChild(container);
    }
    
    //Create a container movieclip (mc) to hold the attached items
    var container:MovieClip = new MovieClip();
    //Attach the container mc to the stage
    addChild(container);
    
    firstEdit();
}

The error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Adsız_02_25_fla::MainTimeline/onNumericStChange()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::NumericStepper/setValue()
at fl.controls::NumericStepper/stepperPressHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::BaseButton/startPress()
at fl.controls::BaseButton/mouseEventHandler()