2012-05-23 33 views
0

我有两个圆圈用不同的颜色和我想要得到的拖累圈一旦用户使用dragend事件的对象去让的填充颜色。找到一个可拖动的形状的填充颜色与Kineticjs

shapes = new Kinetic.Layer(); 

circle1 = new Kinetic.Circle({ 
    x: stage.getWidth()/3.2, 
    y: stage.getHeight()/3.2, 
    radius: radius, 
    fill: "blue", 
    stroke: "black", 
    strokeWidth: 4, 
    name: "circle", 
    draggable: true 
}); 

circle2 = new Kinetic.Circle({ 
    x: stage.getWidth()/1.5, 
    y: stage.getHeight()/1.4, 
    radius: radius, 
    fill: "yellow", 
    stroke: "black", 
    strokeWidth: 4, 
    name: "circle", 
    draggable: true 
}); 

shapes.add(circle1); 
shapes.add(circle2); 
stage.add(shapes); 

回答

1

您可以将处理程序添加到外形和使用getFill()

function iGetFill(){ 
    var color = this.getFill(); 
} 

circle1.on('dragend',function(){ 
    iGetFill.apply(this); 
}); 

circle2.on('dragend',function(){ 
    iGetFill.apply(this); 
}); 
+0

谢谢你,有没有办法让在该层其他各界此值。所以拖CIRCLE1或CIRCLE2需要调用相同的功能。 – Zach

+0

@Zach添加处理程序他们。然后让回调调用一个通用函数。 – Joseph