Cancelling drag

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Cancelling drag

Julien Phalip
Hi,

I'm using DragManager to drag some objects on the interface. And I'd like the dragging to be cancelled when the ESCAPE key is pressed. But I can't find a way to do it since DragManager doesn't seem to have a method for that.

Here's what my code looks like:

    private function keyHandler(event:KeyboardEvent):void {
        if (DragManager.isDragging && event.keyCode == Keyboard.ESCAPE){
            // TODO: Cancel drag here...
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
        }
    }

    public function startDrag(event:MouseEvent):void {
        ...
        DragManager.doDrag(dragInitiator, dragSource, event, image);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
    }

Do you know how I could achieve this?

Thanks a lot,

Julien

Reply | Threaded
Open this post in threaded view
|

Re: Cancelling drag

Josh McDonald-5
I'm trying to figure out a nice way to do this, too. Anybody beat us to it?
I'll owe you a beer :)

-Josh

2009/3/21 Julien Phalip <[hidden email]>

>   Hi,
>
> I'm using DragManager to drag some objects on the interface. And I'd like
> the dragging to be cancelled when the ESCAPE key is pressed. But I can't
> find a way to do it since DragManager doesn't seem to have a method for
> that.
>
> Here's what my code looks like:
>
> private function keyHandler(event:KeyboardEvent):void {
> if (DragManager.isDragging && event.keyCode == Keyboard.ESCAPE){
> // TODO: Cancel drag here...
> stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
> }
> }
>
> public function startDrag(event:MouseEvent):void {
> ...
> DragManager.doDrag(dragInitiator, dragSource, event, image);
> stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
> }
>
> Do you know how I could achieve this?
>
> Thanks a lot,
>
> Julien
>
>  
>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  [hidden email]
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/
Reply | Threaded
Open this post in threaded view
|

Re: Cancelling drag

mitchgrrt-2
In reply to this post by Julien Phalip
I'd like to find a way to cancel a drag programatically too.  Did either of you find out a way to do it?  Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Cancelling drag

dakira
This post has NOT been accepted by the mailing list yet.
Hi guys. I know this is an very old thread but I was recently looking for a solution to this as well. I was looking into the DragManager and it does have a endDrag call but it is private. So, what I did was I took the method implementation of get impl()

private static function get impl():IDragManager
    {
        if (!_impl)
        {
            _impl = IDragManager(
                Singleton.getInstance("mx.managers::IDragManager"));

        }

        return _impl;
    }

and did the same thing where I needed to end the drag from code. Basically the _impl declaration. It seems to work. The only thing I do not do is the tween to send the drag image back to the original location.

Hope that helps,