flexibleChild is a string, which is the id of the flexible child, so using it to reference the object won’t work. Document (which is a model of the MXML document) should be loaded at some point if it’s being used in mxml. I would put a condition to see whether it has been loaded already, and return if it hasn’t. The layout method should be called at least once after the document is loaded, so the logic would apply then.
If the document is never loaded then we have a bigger problem.