I know this post is almost 2 years old, but I just thought I'd share my
solution to other users if they come across the same problem.  I mimic'd the
same sort of behaviour windows does with their drags, such as when you click
to drag a file or folder.  It doesn't actually start the drag until you move
your mouse 5-10 pixels from it's original starting point.  So the idea is to
put the doDrag in the mouseMove event rather than mouseDown.  Then your
click and double click events are not interrupted.

Here's some sample code:

private var _mouseMoveStart:Point;
private function onMouseDown(event:MouseEvent):void
{
        _mouseMoveStart = new Point(this.mouseX, this.mouseY);
        this.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove, false, 0, 
true);
}

private function onMouseMove(event:MouseEvent):void
{
        if (Math.abs(this.mouseX - _mouseMoveStart.x ) < 10 && 
Math.abs(this.mouseY
- _mouseMoveStart.y) < 10)
        {
                return;
        }

        this.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        DragManager.doDrag(this, null, event);
}

You can change "10" to however many pixels you want the mouse to move before
starting the drag.  5-10 seems to be the best.

Cheers ;)

Andrew


KDW wrote:
> 
> Hi.
> 
> I have a list component with items I would like to be able to
> drag-and-drop, but also respond to double clicks.
> 
> I am finding that when a component has a mouseDown handler which calls
> mx.managers.DragManager.doDrag(...) or startDrag() it stops the
> doubleClick event firing (and yes, I have set
> doubleClickEnabled="true" ;-) ).
> 
> I have tried setting the doubleClick action directly on the item
> renderer and setting mx:List/@itemDoubleClick - with the same effect
> in both cases: the doubleClick event fires ok only when I comment out
> the drag operation.
> 
> In some ways this makes sense - the language reference states:
> "For a doubleClick event to occur, it must immediately follow the
> following series of events: mouseDown, mouseUp, click, mouseDown,
> mouseUp. " and I can imagine that the drag start operation is firing
> an event which changes the sequence and stops it being recognised as a
> double click.  However, I would have thought what I want to do is
> perfectly reasonable so should be possible.
> 
> Am I missing something? Or does anyone have a workaround?
> 
> Thanks.
> 
> Kevin.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Doubleclicking-a-component-which-is-draggable-tp14385640p25372913.html
Sent from the Flex Component Development mailing list archive at Nabble.com.

Reply via email to