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?
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. 🙂
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);
}
}
Copy link to clipboard
Copied
JoãoCésar you're great at code. Do you think you can help here?
Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied