DragManager prevents mouse events of children *Updated*
On March 27, 2008, Flash / Flex - 4 CommentsI just ran into another strange behavior of flex. Lets say you have a VBox, with an image inside. When the user clicks the image, it should do some stuff, but when the user clicks (mousedown actually) the VBox it should start dragging. You would expect that when you click the image, both events are fired. This is true when you don’t invoke the dragmanager. If you call the dragmanager, it cancels out all further mouseEvents, thus preventing the code of the image clickhandler to execute.
I hear you thinking “why would you want something like this?”. Well, I’m rebuilding the tree component and I need to have a click event on the icon to open a node. Also I need a mousedown event on the node (icon and label) to enable dragging in the tree. When you call the dragmanager, the click event of the icon doesn’t come through (although sometimes it does…). I created a small test case, which you can view here (source available). Click on the small icon, it will start dragging it and write to the textarea that the mousedown event is received. Now disable the dragmanager and click again, you’ll see that now 2 events are captured.
The problem with this issue is that the mousedown event is fired before the click event, so you’ll never know if the user clicked the icon. Right now, I don’t really have a solution for this issue, maybe I’ll end up rewriting the dragmanager so that it won’t cancel out all events.
Update 03/27/08
I found a work around for this problem. You call the dragmanager at mouseMove, not at mouseDown. If you click now, the click event is fired and the dragmanager is not invoked. But make sure you set a boolean at mouseDown that dragging is allowed and set it to false at mouseUp. Otherwise, flex will allways drag if you move the mouse over the component.
You can see an example here (with source, of course).
What others have to say:
Could you not create a psuedo-Click event? Basically you would create a new MouseEvent, copy all the parameters of the MouseDown event and use Click as the type. Then since the item is a IEventDispatcher, you just tell it to dispatch the event prior to the drag.
Just thinking out load but I did do something like this in the dNdLib – http://code.google.com/p/flex-drag-n-drop-lib/
I needed to replicate mouseEvents and did so pretty easily. Hope that helps.
No, unlike in the example, the image is in another class as the vbox, thus i cannot call it. Furthermore, the ‘imageclass’ is a renderer, which can be changed by the user, my code should never interfere with user code.
I recognize that this is an old post but i came across this page via google and it helped me a little in finding the right way to use the drag manager – and mouseDown seems to be a bad idea in most cases.
When you use mouseMove there is an event property called buttonDown which you can ask instead of implementing mouseUp and -Down and having a boolean flag for that.
Run into the same problem.
Changing MouseEvent.MOUSE_DOWN to MouseEvent.MOUSE_MOVE solved it.
Thanx!
Leave a Reply