Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

HTML5 button function

Contributor ,
Sep 26, 2017 Sep 26, 2017

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

378
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 26, 2017 Sep 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");

}

Translate
LEGEND ,
Sep 26, 2017 Sep 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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 26, 2017 Sep 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");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2017 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 28, 2017 Sep 28, 2017
LATEST

Sorry Colin: User error.

The problem was my fundamental lack of understanding about buttons from the Component window.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines