Problem with expanding/collapsing box

I want to make a drop down menu that appears when the mouse is hovered over a button.
I named the button box 1 and the menu box 2 and I created this code

export function box1_mouseIn(event, $w) {$w(“#box2”).expand();}

export function box1_mouseOut(event, $w) {$w(“#box2”).collapse();}

export function box2_mouseIn(event, $w) {$w(“#box2”).expand();}

export function box2_mouseOut(event, $w) {$w(“#box2”).collapse();}

Box 2 and box 1 are side by side with no gap between them and although the code works quite well the problem I have is that when the mouse goes from box 1 to box 2 and the opposite sometimes box 2 dissapears for a while and then reappears.
It happens very fast,basically it’s more like it flases but I would like to ask if there’s a way to fix it.