Skip to main content
Brucester
Participant
May 17, 2020
Question

Numerous ending }}}}}}}

  • May 17, 2020
  • 2 replies
  • 525 views

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!

 

    This topic has been closed for replies.

    2 replies

    Legend
    May 17, 2020

    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.

    Brucester
    BrucesterAuthor
    Participant
    May 18, 2020
    Hi JC,
    Thank you so much for your response! I knew there was too much nesting and
    wanted to understand how to consolidate. You've been extremely helpful and
    I am grateful for your response.

    I will try your consolidation. Thank you again!



    W. Bruce Howerton, Jr. DDS, MS
    Oral and Maxillofacial Radiologist
    p-(919) 534-7000
    f-(919)-534-7003
    www.carolinaomfimaging.com
    JoãoCésar17023019
    Community Expert
    Community Expert
    May 17, 2020

    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