2012-05-23 4 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

관련 문제