xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Unable to remove event listener
Date Mon, 09 Mar 2009 11:04:16 GMT
Hi Age,

Age Bosma <agebosma@gmail.com> wrote on 03/09/2009 06:28:45 AM:

> This works fine. The event gets triggered as it should. The event is
> used to drag an element. When it gets triggered I'm adding two new
> events to the same element. These get triggered nicely as well but I
> can't get them removed anyone.

   You need to pass the same object as the second argument to 
removeEventListener as you passed to addEventListener.  I
suspect you might be best off passing 'this' for all of the objects
(and setting startX/Y on this on mousedown).

>           ((EventTarget)targetElement).addEventListener("mousemove", new 
DeviceHandler(startX, startY), false);
>           ((EventTarget)targetElement).addEventListener("mouseup", new 
DeviceHandler(), false);
>       }
>       else if (eventType.equals("mousemove")) {
>           double x = position.getX() - startX;
>           double y = position.getY() - startY;
> 
>           System.out.println("Translate: x=" + x + ", y=" + y);
> 
>           targetElement.setAttributeNS(null, "transform", "translate("
> + x + "," + y + ")");
>           targetElement.setAttributeNS(null, "stroke", "rgb(255,0,0)");
>       }
>       else if (eventType.equals("mouseup")) {
>           ((EventTarget)targetElement).removeEventListener("mousemove",
> new DeviceHandler(), false);
>           ((EventTarget)targetElement).removeEventListener("mouseup",
> new DeviceHandler(), false);
>       }
>   }
> 
>   private SVGElement targetElement = null;
>   private MouseEvent event;
>   private float startX = 0;
>   private float startY = 0;
>   private SVGPoint position;
> }
> 
-----------------------------------------------------------------------------------
> 
> Intended bahaviour: mousedown+ mousemove = drag. It should remove the
> 'mousemove' and 'mouseup' again when the button is let go.
> I tried replacing 'new DeviceHandler()' with 'this' when removing the
> events but 'mousemove' nor 'mouseup' gets removed, they remain getting
> triggered. As a result you can't stop dragging the element.
> As I test I even added removeEventListener right after a
> addEventListener but the event does not get removed, it keeps getting
> trigered.
> 
> I'm I doing something completely wrong here?
> 
> Yours,
> 
> Age
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 

Mime
View raw message