在cc.EventListener中碰到的问题


var TwoGameScene = cc.Scene.extend({
 cardArray:null,
 
 onEnter: function(){
 var touchListener = cc.EventListener.create({
 event: cc.EventListener.TOUCH_ONE_BY_ONE,
 swallowTouches: true,
 onTouchEnded: function(touch,event){
 this.moveLeft();
 }


 },
 },
 moveLeft: function(){
 console.log("done");
 return true;
 }
})

 

代码如上,问题是为何this.moveLeft();调用不到,会有异常
TypeError: undefined is not a function (evaluating ‘this.moveLeft()’)

event事件回调回来的this已经不是原来的this对象了。所以需要先保存一个
var selft = this;
{
函数回调内部

self.moveLeft
}

解决了,谢谢