Get shape object from event listener

380 Views Asked by At

The usual procedure to somehow manipulate shapes after some event has happened is well and understood:

var circle = group.createCircle({ cx: 100, cy: 300, r: 50 }).setFill("green").setStroke("pink");
circle.connect("onclick",function(e) {
    circle.setFill("red");
});

Problem is, the graphic i'm working on has been converted from a SVG file into JSON and then loaded into dojox, which means i don't actually have shape objects which i can refer to by variable. So my question is, how do i retrieve shape objects from an even listener? Something like this doesn't work:

...
var group = surface.createGroup();
dojox.gfx.utils.deserialize(group, json);
dojo.connect(group.getEventSource(),"onclick",function(ev) {
    ev.target.setFill('blue');
});

The event target is the actual shape node, not the object so i can't call any dojox methods like setFill()on it. I could use just ordinary SVG DOM methods, but that would break, if dojo was using a different renderer for IE for example.

So can i somehow convert that node into a shape object? I mean, if that doesn't work, what's the point of loading a graphic into dojo like I've described anyway? I feel like i'm missing something obvious here.

1

There are 1 best solutions below

0
DanMan On

This works:

group.connect("onclick",function(ev) {
    ev.gfxTarget.setFill('#ff0000');
});

instead of how the docs currently suggest: using the onmouseclick event. Then you can access the shape object as gfxTarget property of the event object.