javascript - Making JS "this" work in prototype function -


Being new to javascript, understanding of this is somewhat unstable. I have read some articles and many Posted something and learned a bit, but I'm having problems implementing some codes. I am using the KineticGS library to implement some canvas operations. I was working with one and was able to get an image to resize with mouse control, however, when I put the code into a prototype function, it was not working again.

  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

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -