Nic
Nic

Reputation: 65

Flex 3: determine if an event target is a descendant of a component

I have a custom component with a couple of text input fields (among other things) that is used as the row components in a tree. I have had to write my own drag and drop handling, and have almost finished the start handler (which I did last), using mouseDown as the event to kick if off.

It basically works, but when the tree is expanded enough so that a scroll bar shows, using the scroll bar drags a row of the tree at the same time ! Not the desired behaviour.

Looking in the debugger, I can see that when a row of the tree is dragged the currentTarget is the tree itself, and the target is the textInput component. Looking at the parents of that component I can see my custom component (that contains the textInput) a couple of levels up.

My question is, is there an easy way to determine if this target is descended from my component, so that I can initiate a drag only if that is the case ?

event.target is doesn't work by the way....which I kind of expected, because it isn't !

Thanks,

Mike

Upvotes: 0

Views: 348

Answers (2)

Tom Chiverton
Tom Chiverton

Reputation: 677

You could create a 'marker' interface (i.e. one with no methods or properties) , and then ask

if ( yourObject is IYourInterface) {

in your code.

Upvotes: 1

Maxim Kachurovskiy
Maxim Kachurovskiy

Reputation: 3022

Use myComponent.contains(child).

P.S: It also returns true when myComponent == child.

Upvotes: 1

Related Questions