I'm trying to check if a clicked element is inside of an IVisualElement in Flex 4. So I want something like "if this element is in this element, then execute function".
I'm a开发者_C百科ware of the 'parent' property but this doesn't seem to work when my element is not a direct child of the element but for example 3 levels deep.
Can anyone help me out with this?
Traverse up through the display list until you hit either an IVisualElement or the Stage. If you hit Stage, you lose.
function isInsideIVisualElement(child:DisplayObject):Boolean
{
var p = child.parent;
while(p != null)
{
if(p is Stage)
return false;
if(p is IVisualElement)
return true;
p = p.parent
}
//p is null
return false;//or throw error: child is not addChilded to begin with
}
加载中,请稍侯......
精彩评论