I am creating rectangle nodes with a for() statement and now I need to get the reference to each one. There seams to to be some black magic going on to create these canvas objects ,so it makes it hard to access items without ids to reference.
Can someone clear this up or point me in the right direction?
for(x=1;x<=8;x++)
{
var rect = new Kinetic.Rect({
x: 300,
y: 80+offset,
width: 60,
height: 20,
fill: 'white',
stroke: 'black',
strokeWidth: 1,
draggable: false
});
rect.on('mouseover', function() {
writeMessage(messageLayer, this.getY());
});
// add the shape to the layer
layer.add(rect);
offset += 120;
Thanks
You should be able to access each of them buy using
layer.getChildren();, which will return all of them, or if you know which one you need,layer.getChildren()[0];, which will get the first one.Though I would give them each a name to make it a bit easier.
Then you can use
layer.get('.rct3');orlayer.get('.rct3')[0];.