Search code examples
easeljscreatejsevent-listener

Access class properties from CreateJS event listener function?


I'm pretty new to JavaScript and CreateJS.
Here is my code:

var ClassName = function(){
this.mc = new createjs.MovieClip();
//...Add graphic to this.mc code
createjs.Tween.get(this.mc).to({scaleY:0, y:50},300).call(onTweenCompleted);
}
ClassName.prototype.onTweenCompleted = function(){
console.log(this.mc.y);
}

My problem is that when TweenComplete call onTweenCompleted properties this.mc.y is not accessible. Here an error I got:

Uncaught TypeError: Cannot set property 'y' of undefined


Solution

  • You should add a scope in the function call e.g. like this:

    createjs.Tween.get(this.mc).to({scaleY:0, y:50},300).call(onTweenCompleted, [], this);