开发者

Check if clicked element is inside of IVisualElement (parent)

开发者 https://www.devze.com 2023-01-01 01:13 出处:网络
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 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

精彩评论

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

关注公众号