You need to bind the 'this' to the functions you are using as callbacks.

 this.canvas.addEventListener('touchstart',this.onMouseDown.bind(this));

Otherwise  for dom events handlers the this would be the DOM element that
the event triggered on

To read more about it
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

On Wed, May 13, 2015 at 4:20 PM, Dinesh Guleria <[email protected]>
wrote:

> Hi,
>
> My html app uses the mouseup & mouse down event with the constructor
> function & an input image.
> It use to work fine as per my expectation.
>
> I am use crosswalk webview in my cordova project.
>
> Now as mouseup & mousedown event does not works in android app so same i
> have changed to touchstart & touchdown events.
>
> But My touchstart & touchdown events are not working as per expectation.
>
> Here i am binding the touchstart & touchdown events of the input image.
> this.canvas is the ID of an input image.
>
>
> ======================== code is something like this
> =============================
>
> // create new instance
> var button   = new my_func("one");
> var button_1 = new my_func("two");
>
>
>
> funtion my_func(canvasName)
> {
>
>    this.bDisabled = false;
>
>    this.canvas = document.getElementById(canvasName);
>
>    // add event listner
>    this.canvas.addEventListener('touchstart',this.onMouseDown);
>    this.canvas.addEventListener('touchend',this.onMouseUp);
>
> }
>
>
> my_func.prototype.onMouseDown = function()
> {
>     alert('down');
>     alert(this.bDisabled);
> }
>
>
> my_func.prototype.onMouseUp = function()
> {
>
>     alert('up');
>     alert(this.bDisabled);
> }
>
> =====================================================
>
> Why alert(this.bdisable) gives output as 'undefined' when input image is
> pressed down & up?
> Means both the event handlers are not able to detect the variable
> this.bDisabled ?
>
> How to bind the events correctly so that event handler will be able to
> access the data initialised inside myfun() ?
>
> Please suggest.
>
> Regards,
> Dinesh
>
> _______________________________________________
> Crosswalk-help mailing list
> [email protected]
> https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help
>
>
_______________________________________________
Crosswalk-help mailing list
[email protected]
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help

Reply via email to