Highlighted

Button function doesn't work (HTML5)

Community Beginner ,
Oct 15, 2019

Copy link to clipboard

Copied

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.png

clipboard_image_1.png

clipboard_image_2.png

TOPICS
Error, Other

Views

206

Likes

Translate

Translate

Report

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

Button function doesn't work (HTML5)

Community Beginner ,
Oct 15, 2019

Copy link to clipboard

Copied

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.png

clipboard_image_1.png

clipboard_image_2.png

TOPICS
Error, Other

Views

207

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 15, 2019 0
Adobe Community Professional ,
Oct 15, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2019 0
Community Beginner ,
Oct 15, 2019

Copy link to clipboard

Copied

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);

}

}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2019 0
Adobe Community Professional ,
Oct 15, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2019 1
Community Beginner ,
Oct 16, 2019

Copy link to clipboard

Copied

y'all still there?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2019 0
Adobe Community Professional ,
Oct 16, 2019

Copy link to clipboard

Copied

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

 

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2019 1
Community Beginner ,
Oct 16, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2019 0
Community Beginner ,
Oct 17, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 17, 2019 0