Sketch.js pageX undefined error

I am using sketch.js by intridea in a phonegap application. It works in full accordance with the modification

case 'touchstart': if (this.painting) {//add this.stopPainting(); //add }//add this.startPainting(); break; 

adding the above lines to the code. But I get a pageX undefined error that crashes my application.

 01-23 19:53:59.342: E/Web Console(31932): Uncaught TypeError: Cannot read property 'pageX' of undefined at file:///android_asset/www/js/external_libs/sketch.js:107 

How to overcome this problem, any help would be appreciated. thanks

+1
javascript jquery html5-canvas cordova
source share
1 answer

Everyone seems to have turned to jqscribbel.js, but to directly answer this question with sketch.js you need to check if e.originalEvent.targetTouches[0] exists. I have not dug sketch.js yet, but it seems that when the touchup event fires, e.originalEvent.targetTouches[0] no longer detected, so trying to find .pageX of undefined gives an error. This error causes the entire canvas to be redrawn, so you cannot draw more than one sketch on the canvas. To fix this error, simply add find the following two lines of code (around line 100/101):

 e.pageX = e.originalEvent.targetTouches[0].pageX; e.pageY = e.originalEvent.targetTouches[0].pageY; 

and replace with

 if (e.originalEvent.targetTouches[0] !== undefined && e.originalEvent.targetTouches[0].pageX !== undefined){ e.pageX = e.originalEvent.targetTouches[0].pageX; } if (e.originalEvent.targetTouches[0] !== undefined && e.originalEvent.targetTouches[0].pageY !==undefined){ e.pageY = e.originalEvent.targetTouches[0].pageY; } 
+10
source share

All Articles