Witam, mam taki problem, tworze obiekt kin w konstruktorze, jest on dostepny w funkcji drawImage(), natomiast w funkcji dragger() występuje błąd, że kin jest nie zdefiniowane. Mógł by ktoś poradzić mi dlaczego ? Z góry dziękuję.
<!DOCTYPE HTML>
<html>
<head>
<script src="Kinetic-v1.0.0.js"></script>
<script type = "text/javascript">
function Obrazek(obiekt)
{
this.kin = new Kinetic_2d("obraz");
this.rectX = 0;
this.rectY = 0;
this.rectOfsetX = 0;
this.rectOfsetY = 0;
this.dragingRect = false;
this.boba = obiekt;
this.canvas=null;
this.context=null;
this.dragger = function ()
{
var mouseP = this.kin.getMousePos(); // bląd kin jest nie zdefiniowane
if(this.dragingRect)
{
this.rectX = mouseP.x - rectOfsetX;
this.rectY = mouseP.y - rectOfserY;
}
this.kin.clear();
this.kin.beginRegion();
this.context.drawImage(this.boba,rectX,rectY,this.boba.width,this.boba.height);
this.context.beginPath();
this.context.rect(this.rectX,this.rectY,this.boba.width,this.boba.height);
this.context.closePath();
this.kin.addRegionEventListener("onmousedown",function(){
var mouseP = this.kin.getMousePos();
this.dragingRect = true;
this.rectOfsetX = mouseP.x - this.rectX;
this.rectOfsetY = mouseP.y - this.rectY;
});
this.kin.addRegionEventListener("onmouseup",function(){
this.dragingRect = false;
});
this.kin.addRegionEventListener("onmouseover",function(){
document.body.style.cursor = "pointer";
});
this.kin.addRegionEventListener("onmouseout",function(){
document.body.style.cursor = "default";});
this.kin.closeRegion();
}
this.drawImage = function()
{
this.canvas = this.kin.getCanvas();
this.context = this.kin.getContext();
this.rectX = this.canvas.width/2 - this.boba.width/2;
this.rextY = this.canvas.height/2 - this.boba.height/2;
this.kin.setDrawStage(this.dragger);
}
}
window.onload = function(){
var im = new Image();
im.onload = function()
{
var zdj = new Obrazek(im);
zdj.drawImage();
}
im.src ="Garnek.jpg";
}
</script>
</head>
<body>
<canvas id="obraz" width="400" height="400" style="border-style:solid;" >
Twoja przegladarka nie obsluguje canvas.
</canvas>
</body>
</html>