Skip to main content
Inspiring
January 16, 2022
Answered

Error Uncaught TypeError: Cannot read properties of undefined (reading 'tweenjs_count')

  • January 16, 2022
  • 2 replies
  • 5534 views

 

 

 

setTimeout(function () {
var photo2Sound = createjs.Sound.play("crocodile", { volume: 1 });
photo2Sound.on("complete", photoSoundCompleteHandler, this);
}, 2000);

 

Hi. I'm working with canvass. I get an error with the above code. I'm not sure what I am doing wrong. 

When the sound completes, I am trying to call the photoSoundComplete() function.

 

Uncaught TypeError: Cannot read properties of undefined (reading 'tweenjs_count')

 

Any help would be appreciated.

Thanks

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi . yes, I got underfined

     

     


    So create a reference to the current timeline and send it as an argument of the on method inside of the setTimeout method. Like this:

    var _this = this;
    
    setTimeout(function () {
    var photo2Sound = createjs.Sound.play("crocodile", { volume: 1 });
    photo2Sound.on("complete", photoSoundCompleteHandler, _this); // update here
    }, 2000);

     

    Regards,

    JC

    2 replies

    Inspiring
    January 17, 2022

    Hi - I'm sorry. The error is a tween error which is called in 

    photoSoundCompleteHandler

    I use this tween for the target "king"

    createjs.Tween.get(this.king, {override:true}).to({y:578}, 1000, createjs.Ease.bounceOut);

    Then I play a sound. When it completes I call soundCompleteHandler to tween "king" back to another position.

    It looks like there is a problem tweeting the same target. BUT I thought that override solved that,

    function soundCompleteHandler ()
    {
    	createjs.Tween.get(this.king, {override:true}).to({y:1085}, 1000, createjs.Ease.bounceOut);
    }

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 17, 2022

    OK.  No problem.

     

    I think it's a context problem.

     

    If you run...

    console.log(this.king);

     

    ... inside of the soundCompletHandler function, you will probably get undefined. Can you confirm this?

    Inspiring
    January 17, 2022

    Hi . yes, I got underfined

     

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 16, 2022

    Hi.

     

    Here it worked without a problem.

     

    Since the error refers to a property called tweenjs_count, are you sure it's not coming from somewhere else?

     

    Please let us know.

     

    Regards,

    JC