Skip to main content
paul_james123
Inspiring
September 26, 2017
Answered

HTML5 button function

  • September 26, 2017
  • 1 reply
  • 475 views

Hi All,

Wondering what I'm doing wrong. Why doesn't this work in my Animate CC, HTML5 project? (probably something obvious)

stage.btn1_INS.addEventListener("click", buttonClick.bind(this));

function buttonClick() { 

alert("I am active");

}

btn1_INS is a Symbol with a type of Button.

Thanks

    This topic has been closed for replies.
    Correct answer Colin Holgate

    The top level of the timeline need not be the same thing as 'stage', I think mainly because of the new camera features. You would normally say:

    this.btn1_INS.addEventListener("click", buttonClick.bind(this));

    function buttonClick() { 

        alert("I am active");

    }

    1 reply

    Colin Holgate
    Colin HolgateCorrect answer
    Inspiring
    September 26, 2017

    The top level of the timeline need not be the same thing as 'stage', I think mainly because of the new camera features. You would normally say:

    this.btn1_INS.addEventListener("click", buttonClick.bind(this));

    function buttonClick() { 

        alert("I am active");

    }

    paul_james123
    Inspiring
    September 26, 2017

    Must be something else. That doesn't work either... But if I put the listener on the header image (that is a Movie Clip) it works.

    this.header_INS.addEventListener("click", buttonClick.bind(this)); //This works

    this.btn1_INS.addEventListener("click", buttonClick.bind(this)); //This doesn't


    function buttonClick() { 

        alert("I am active");

    }

    Colin Holgate
    Inspiring
    September 26, 2017

    Check whether the btn1_INS has had that name since the start of the timeline. If you have key frames and you have the symbol named after the keyframe but not before, then it will fail.

    Also, if btn1_INS is in fact a Button, and header_INS is a movieclip, check the Hit frame inside the button has something there.