getParentByName, just because
In talking offline with simplexian, the idea of a getParentByName function came up. I figured it might be useful to many of us.
Code:
public static function getAncestorByName(d:DisplayObject, name:String):DisplayObject{
var p:DisplayObject = d;
while ((p != null) && (p.name != name)){
p = d.parent;
}
return p;
}
And here's one that may be more useful, to get a parent by Class. This will return the first ancestor that IS an instance of clazz or anything extending it, but if you replace is with instanceof, it'll look for the exact matching class.
Code:
public static function getAncestorByClass(d:DisplayObject, clazz:Class):DisplayObject{
var p:DisplayObject = d;
while ((p != null) && !(p is clazz)){
p = d.parent;
}
return p;
}
All code untested. Please give feedback.
Edit: was confused about DisplayObjects and DisplayObjectContainers.