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

Button function doesn't work (HTML5)

Community Beginner ,
Oct 15, 2019 Oct 15, 2019

button's function doesn't work(wronganswer5), even though the function worked on the last buttons(wronganswer1, wronganswer2). Its function is supposed to decrease the Health Bar. Can anyone point out what I'm doing wrong here? or is the software the problem?

clipboard_image_0.pngexpand image

clipboard_image_1.pngexpand image

clipboard_image_2.pngexpand image

TOPICS
Error , Other
604
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
Community Expert ,
Oct 15, 2019 Oct 15, 2019

Can you just copy the code into the message board so its easier to read? Or add bigger photos. Please. 🙂

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
Community Beginner ,
Oct 15, 2019 Oct 15, 2019

1st screenshot:

this.stop();

 

this.wronganswer5.addEventListener("click", fl_ClickToGoToAndPlayFromFrame_14.bind(this));

function fl_ClickToGoToAndPlayFromFrame_14()
{
decreaseHealthF(638);
}

 

2nd screenshot:

this.wronganswer1.addEventListener("click", decreaseHealthF.bind(this));

function fl_MouseClickHandler_3()
{
decreaseHealthF
}


this.wronganswer1.addEventListener("click", fl_ClickToGoToAndPlayFromFrame_7.bind(this));

function fl_ClickToGoToAndPlayFromFrame_7()
{
this.play();
}

 

3rd screenshot:

 

var tl=this;

var originalHealth=100;

function decreaseHealthF(){

tl.healthBar.scaleX-=15/originalHealth;

if(tl.healthBar.scaleX<=0){

tl.healthBar.scaleX=0;

this.gotoAndStop(1);

}

}

 

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
Community Expert ,
Oct 15, 2019 Oct 15, 2019

JoãoCésar you're great at code. Do you think you can help here?

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
Community Beginner ,
Oct 16, 2019 Oct 16, 2019
y'all still 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
Community Expert ,
Oct 16, 2019 Oct 16, 2019

Hi.

 

Things are not working probably because you're trying to access a variable and function that are not available in all frames.

 

When declaring variables, defining functions, creating properties and methods in Animate CC, things work like this:

 

var greetings = "Hello!"; // this variable will only be available in the current frame

this.greetings = "Hello!"; // this property will be avaible for the entire timeline

greetings = "Hello!"; // this is a global property. It's the same as window.grettings. It will be available anywhere


function sayHello(){console.log("Hello!");}; // this function will only be available in the current frame

this.sayHello = function(){console.log("Hello!");}; // this method will be avaible for the entire timeline

sayHello = function(){console.log("Hello!");}; // this is a global method. It's the same as window.sayHello = function(){console.log("Hello!");};. It will be available anywhere

 

So, in your case, your originalHealth variable should be a property of the main timeline (this.originalHealth) and the decreaseHealthF function should be a method of the main timeline (this.decreaseHealthF).

 

Please let us know if this helps you solve the issue.

 

 

Regards,

JC

 

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
Community Beginner ,
Oct 16, 2019 Oct 16, 2019

Thank you for your response, I tried changing the actions of my health bar frame into this:

 

 

var tl=this;

 

this.originalHealth=100;

 

this.decreaseHealthF = function(){

tl.healthBar.scaleX-=15/originalHealth;

if(tl.healthBar.scaleX<=0){

tl.healthBar.scaleX=0;

this.gotoAndStop(1); // define this

}

}

 

 

and the button's functions into:

 

this.decreaseHealthF;

 

 

I tried what you said, but the buttons themselves don't work anymore, even the ones without decreaseHealthF. What's wrong?

the health bar's instance name is healthBar btw, just in case that's needed.

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
Community Beginner ,
Oct 17, 2019 Oct 17, 2019
LATEST
hey, sorry if I'm being one heck of a bother right now, but I need help please. It's the last bit of information I need.
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