New to code: help with if/else mouseIn

Hi there, I’m trying to create a rule where when I mouse out of a button ‘buttonServiceExpanded’, if the cursor has moved into the region ‘ServicesMenu’ then the ‘MegaMenu’ state changes to ‘MenuExpandedServices’…otherwise its state changes to ‘MenuCollapsed,’

See my code below, I hope that helps. I think what I have wrong is the second line of code (the ‘if’ rule). Can anyone help? I’m hoping its just something really simple I’ve missed, I’m very new to this and trying to learn. Thanks in advance.

export function buttonServicesExpanded_mouseOut(event) {
 if (ServicesMenu_mouseIn) {
                $w('#MegaMenu').changeState("MenuExpandedServices");
        } 
 else {
                $w('#MegaMenu').changeState("MenuCollapsed");       
        }
}
$w.onReady(function () {
    $w('#myButton').onMouseOut(()=>{
        $w('#MegaMenu').changeState("MenuExpandedServices");
    })
    
   $w('#myButton').onMouseIn(()=>{
        $w('#MegaMenu').changeState("MenuCollapsed");      
    })
})

Take also a look into this post…

It will help you understanding coding-structure a little bit better.

Thanks so much :slight_smile: