I have an event driven flash program. I need to be able to call removeChild() if and only if an object is a child. getChildByName() and most other functions don’t seem to allow for this and if you call removeChild() on an object that isn’t a child it will throw an error. I suppose an option may be to catch the thrown error and just ignore it, but that seems like a bad solution.
Any help is appreciated!
To avoid errors I normally just wrap
removeChild()inif(parent):If the sprite doesn’t have a parent, null will be given in the
if()meaningremoveChild()won’t be called.removeChild()is also run from theparentof the child (which we have already confirmed exists in theif()statement around it). This means the targeted parent is always the owner of the child.parentis often forgotten but is an extremely powerful property for simplifying allDisplayListrelated operations.