Copy link to clipboard
Copied
Can this be consolidated without adding numerous }}}}} when closing the code?
var _this = this;
stage.enableMouseOver(3);
this.front_btn.addEventListener("mouseover", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "Frontal Bone";
this.front_btn.addEventListener("mouseout", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "";
this.nasal_btn.addEventListener("mouseover", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "Nasal Bone";
this.nasal_btn.addEventListener("mouseout", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "";
this.frontal_sinus_btn.addEventListener("mouseover", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "Frontal Sinus";
this.frontal_sinus_btn.addEventListener("mouseout", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "";
this.cg_btn.addEventListener("mouseover", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "Crista Gali";
this.cg_btn.addEventListener("mouseout", buttonF.bind(this));
function buttonF(){
this.mytext1.text = "";
}}}}}}}};
Thank you in advance!
Copy link to clipboard
Copied
Hi.
All this nesting is certainly not necessary.
You can define the functions and add the listeners in the same context/level.
Something like this:
var _this = this;
function mouseOverHandler0()
{
_this.text0.text = "mouse over text 0";
}
function mouseOutHandler0()
{
_this.text0.text = "mouse out text 0";
}
function mouseOverHandler1()
{
_this.text1.text = "mouse over text 1";
}
function mouseOutHandler1()
{
_this.text1.text = "mouse out text 1";
}
stage.enableMouseOver(3);
this.yourButton0.addEventListener("mouseover", mouseOverHandler0);
this.yourButton0.addEventListener("mouseout", mouseOutHandler0);
this.yourButton1.addEventListener("mouseover", mouseOverHandler1);
this.yourButton1.addEventListener("mouseout", mouseOutHandler1);
Please let us know exactly what you want to achieve.
Regards,
JC
Copy link to clipboard
Copied
I'd like to verify that it's not nesting function declarations seven levels deep that's bothering you, but rather it's literally just the row of closing braces that you don't like the look of.
I'm having a hard time imaging how this code would even behave. You have eight event handler functions with the exact same name, and it looks like... triggering them adds the next one in the sequence one by one? That can't be intended behavior.
Copy link to clipboard
Copied