开发者

Check if clicked element is inside of IVisualElement (parent)

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜