[SOLVED] Uncaught TypeError: Cannot read property 'sound' of undefined

I’m getting this error when i want to pause music.
I’ve created an entity called UserInterface which contains two components:
First component is my sound and the second is my script.
My scene is : PlayCanvas | HTML5 Game Engine
When i click the secod button i want to pause the music but i get this error.
Could somebody tell me what’s the problem?

Change musicButton to:

User.prototype.musicButton = function(event) {
    // get button element by class
    var button2 = this.div.querySelector('.button2');
    // add event listener on `click`
    button2.addEventListener('click', function() {
          if (playing) {
             playing = false;
          else if (!playing){
             playing = true;

Read all about bind here.

1 Like

Thank you very much!