This code throws an error:
if (modalMessage != null && contains(modalMessage))
{
removeChild(modalMessage); // the error is here
modalMessage = null;
}
The Error is:
[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
how can this be? i am checking if it is a child beforehand.
contains()will return true if the subject is a descendant of the caller. This will return true for indirect descendants too, children of children etc.http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#contains%28%29
You could check the parent:
Or, for a more general purpose disposal solution: