Re: [flexcoders] Letting parents handle drag events
Is there a reason you can't use capture phase listeners? I definitely can, and that's the solution I'm going to use. It just didn't occur to me because: a) I was working in MXML and was just attaching listeners using attributes. b) DragEvent inherits from MouseEvent, which to me at least, implies that it behaves like MouseEvent, which means a default of bubbling (even though the MouseEvent constructor indicates the default is to not bubble, which I assume is just in keeping with Event's constructor's default arguments). So, my problem is now solved... I just think both of these issues should be raised somewhere officially so others don't bang their head on it quite as much as I did. The two points that need to be made: - MXML event attributes are added with the defaults, which means *not* the capture phase. - DragEvents don't bubble like MouseEvents, so if you need to get them higher up the hierarchy you have to capture them. Troy.
RE: [flexcoders] Letting parents handle drag events
Troy - drag events are dispatched to what _you_ attach them to. If you want the event to spawn from a child - but be handled by the parent... you should override addChild in the parent and attach the listener there. Your handler will be in the parent and each child will announce whatever event you attach to it at that level. Rick Winscot -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Troy Gilbert Sent: Monday, April 14, 2008 11:56 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Letting parents handle drag events So. are you _not_ using the dragSource, dragInitiator or draggedItem provided by your drag/drop events? I would recommend that first before you try to get list items to dispatch events. Uhm, I think you're missing my question. I'm trying to use all of those things, but I can't because I'm not getting the drag events. And this isn't an actual list component, it's a canvas full of controls (controls witch initiate the drag events) and another similar container full of these controls, and I need to detect when controls dragged from one are dragged onto controls in the other. And I'd prefer for the parent's owner to handle this instead of building the logic into the component itself. Just like I'd have it handle any other event (at least any other event that traverses the DisplayList, like a MouseEvent, which being the super class of DragEvent would imply that DragEvent works similarly, but it doesn't... As for the second question, the mouse must participate in a drag/drop operation - but the actual functionality of dragging and dropping is a lower level operation that isn't directly tied to a components condition. If you wanted to turn drag/drop off based on mouse enabled or something similar. then all you had to do is check for myComponent.mouseEnabled with your drag start event. and if this fails. event.preventDefault(). The point is that the drag events don't fire correctly *because* they don't work like mouse events, but they should. This is a known bug (in Adobe DB and confirmed) and I've already fixed it to a degree. Troy. -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
Re: [flexcoders] Letting parents handle drag events
Troy - drag events are dispatched to what _you_ attach them to. If you want the event to spawn from a child - but be handled by the parent... you should override addChild in the parent and attach the listener there. Your handler will be in the parent and each child will announce whatever event you attach to it at that level. For my case, I can't actually do that because they're not direct child components, their actually grandchildren, created and managed by the container (which is the child). Sure, I'd still the get the addChild events, and I could look for children of a specific type (since they're a specific custom type in my case), but that's not very robust. And it doesn't fundamentally fix the problem. The problem is that Adobe derives the DragEvents from the MouseEvent class but doesn't dispatch it according to the same logic. If add a mouseDown event on a grandparent component and the user clicks on a grandchild component, unless the grandchild stops the event propogation the grandparent will get a notification, and it can identify the grandchild through the event.target property. With drag events, they aren't dispatched through the DisplayList like a MouseEvent, they're dispatched by hand by the DragProxy class. And because they're dispatched by hand, the event's target and currentTarget properties are always identical. Which is not like MouseEvents at all... Hmm... looking again at the DragProxy's event dispatch... we could make it work by changing the constructor for the DragEvent, passing in true for bubbles. This will actually fix the problem, and is probably how it should work since mouse events bubble. I could also use capture-phase event listeners, because even though the event doesn't bubble, it should always go through the capture phase (or at least that's the impression I get from the docs). This hadn't even occured to me because I was using MXML and the event attributes on components are not capture-phase event listeners, they are target and bubbling-phase listeners (useCapture=false in their addEventListener calls). So, I guess I've fixed my problem.. I've already got a monkey-patched DragProxy so that I could (properly) test for mouseEnabled when finding drop targets. I'll just add the above fix so that the DragEvents bubble. Adobe guys, is my reasoning here sensible? Troy.
RE: [flexcoders] Letting parents handle drag events
Is there a reason you can't use capture phase listeners? From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Troy Gilbert Sent: Tuesday, April 15, 2008 10:19 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Letting parents handle drag events Troy - drag events are dispatched to what _you_ attach them to. If you want the event to spawn from a child - but be handled by the parent... you should override addChild in the parent and attach the listener there. Your handler will be in the parent and each child will announce whatever event you attach to it at that level. For my case, I can't actually do that because they're not direct child components, their actually grandchildren, created and managed by the container (which is the child). Sure, I'd still the get the addChild events, and I could look for children of a specific type (since they're a specific custom type in my case), but that's not very robust. And it doesn't fundamentally fix the problem. The problem is that Adobe derives the DragEvents from the MouseEvent class but doesn't dispatch it according to the same logic. If add a mouseDown event on a grandparent component and the user clicks on a grandchild component, unless the grandchild stops the event propogation the grandparent will get a notification, and it can identify the grandchild through the event.target property. With drag events, they aren't dispatched through the DisplayList like a MouseEvent, they're dispatched by hand by the DragProxy class. And because they're dispatched by hand, the event's target and currentTarget properties are always identical. Which is not like MouseEvents at all... Hmm... looking again at the DragProxy's event dispatch... we could make it work by changing the constructor for the DragEvent, passing in true for bubbles. This will actually fix the problem, and is probably how it should work since mouse events bubble. I could also use capture-phase event listeners, because even though the event doesn't bubble, it should always go through the capture phase (or at least that's the impression I get from the docs). This hadn't even occured to me because I was using MXML and the event attributes on components are not capture-phase event listeners, they are target and bubbling-phase listeners (useCapture=false in their addEventListener calls). So, I guess I've fixed my problem.. I've already got a monkey-patched DragProxy so that I could (properly) test for mouseEnabled when finding drop targets. I'll just add the above fix so that the DragEvents bubble. Adobe guys, is my reasoning here sensible? Troy.
[flexcoders] Letting parents handle drag events
I have a custom container full of items (basically a list). I need to determine when the user drags and drops something onto one of those items. I was hoping I could just add a listener to the list container and that the drag events it received would contain the child object as the event.target (just like mouse events). Instead, the list container is both the target and current target. Is there a way to get the result I want? The list items are getting the drag events, I just need them to also be dispatched from the parent, and I don't want to have to create a custom event to handle this. And in general, why is it that the DragEvents inherit from MouseEvents but don't *behave* like mouse events? For example, they don't respect mouseEnabled/mouseChildren (I had to change DragProxy to do this). Thanks for the help, Troy.
RE: [flexcoders] Letting parents handle drag events
So. are you _not_ using the dragSource, dragInitiator or draggedItem provided by your drag/drop events? I would recommend that first before you try to get list items to dispatch events. As for the second question, the mouse must participate in a drag/drop operation - but the actual functionality of dragging and dropping is a lower level operation that isn't directly tied to a components condition. If you wanted to turn drag/drop off based on mouse enabled or something similar. then all you had to do is check for myComponent.mouseEnabled with your drag start event. and if this fails. event.preventDefault(). Rick Winscot From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of thirtyfivemph Sent: Monday, April 14, 2008 3:27 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Letting parents handle drag events I have a custom container full of items (basically a list). I need to determine when the user drags and drops something onto one of those items. I was hoping I could just add a listener to the list container and that the drag events it received would contain the child object as the event.target (just like mouse events). Instead, the list container is both the target and current target. Is there a way to get the result I want? The list items are getting the drag events, I just need them to also be dispatched from the parent, and I don't want to have to create a custom event to handle this. And in general, why is it that the DragEvents inherit from MouseEvents but don't *behave* like mouse events? For example, they don't respect mouseEnabled/mouseChildren (I had to change DragProxy to do this). Thanks for the help, Troy. image001.jpgimage002.jpg
Re: [flexcoders] Letting parents handle drag events
So… are you _not_ using the dragSource, dragInitiator or draggedItem provided by your drag/drop events? I would recommend that first before you try to get list items to dispatch events… Uhm, I think you're missing my question. I'm trying to use all of those things, but I can't because I'm not getting the drag events. And this isn't an actual list component, it's a canvas full of controls (controls witch initiate the drag events) and another similar container full of these controls, and I need to detect when controls dragged from one are dragged onto controls in the other. And I'd prefer for the parent's owner to handle this instead of building the logic into the component itself. Just like I'd have it handle any other event (at least any other event that traverses the DisplayList, like a MouseEvent, which being the super class of DragEvent would imply that DragEvent works similarly, but it doesn't... As for the second question, the mouse must participate in a drag/drop operation – but the actual functionality of dragging and dropping is a lower level operation that isn't directly tied to a components condition. If you wanted to turn drag/drop off based on mouse enabled or something similar… then all you had to do is check for myComponent.mouseEnabled with your drag start event… and if this fails… event.preventDefault(). The point is that the drag events don't fire correctly *because* they don't work like mouse events, but they should. This is a known bug (in Adobe DB and confirmed) and I've already fixed it to a degree. Troy. -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/