if(stage.focus != stage) { var obj:DisplayObject = stage.focus; while(obj != stage) { if(obj == null || !obj.visible) { stage.focus = stage; break; } else { obj = obj.parent; } } }