var myparent:DisplayObjectContainer = parent as DisplayObjectContainer; if (myparent) if (myparent.contains(this)) removeChild(this);