Error from removeChildAt

I keep getting an “Error #1009: Cannot access a property or method of a null object reference” off the following function. Any ideas why?

    public function sendComplete_logout( e:Event ):void {
        trace(parent.numChildren);//currently equals 22
        while(parent.numChildren>=0){parent.removeChildAt(0);}
    }