views:

44

answers:

1

Hi,

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 aware 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?

+1  A: 

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
}
Amarghosh
I changed that a bit and it works now, thanks!
PhysX