javascript - Making JS "this" work in prototype function -
Being new to javascript,
canvas.protipipip.edimg = function () {var self = this; Var image; Var imageObj = new image (); ImageObj.onload = function {image = new Kinetic.Image ({x: 200, Y: 50, image: imageObj, width: 106, height: 118, draggable: false}); Self.backgroundLayer.add (image); Self.stage.add (self.backgroundLayer); }; ImageObj.src = 'http://www.html5canvastutorials.com/demos/assets/yoda.jpg'; Up CIRCLE1 = new Kinetic.Circle ({x: 150, Y: 150, radius: 10, fill: 'red', stroke: 'black', strokeWidth: 4, dragable: false}); Circle1.isResizing = false; Circle1.on ("click", function (e) {// toggle resize isResizing on right / wrong = this.isResizing;; this.setDraggable (isResizing); self.backgroundLayer.setDraggable (isResizing);; this.setFill (IsResizing? "Green": "red")); this.isResizing = isResizing; self.backgroundLayer.draw ();}); Circle1.on ("dragmove", function () {if (this.isResizing) {var position = this.getPosition (); var x = pos.x; on y = pos.y; on rectx = image.getX () ; Var Rectivi = Image .getY (); Image. Sets (X - Rectix, Y - Rickety); Self Background Background;)}; Self.backgroundLayer.add (CIRCLE1); Self.backgroundLayer.draw (); }
I'm assuming the problem that there is a problem using the function this
, but I'm not sure how to fix the problem tell me someone What can be the problem and I will fix it?
After the
I can see a problem with the line that is setting the size of the image:
image.setSize (x - rectX, y - rectY); For example if you have x 100 and rectX 200, then you have the width of '-100', which ends with Not legal. In the fleet you provided, when I use constant values, the image is completely shaped:
rect.setSize (200, 200) );
.
Comments
Post a Comment