Code optimization
I have four buttons. When you hover the mouse cursor over one of the buttons, an inscription appears in the text field, when the cursor goes beyond the button, the text disappears. The code looks very large, although parts of it are repeated. Is there any way to reduce (optimize) this code?
My main project uses more than 50 buttons (That's a lot of code!)
function OUT(e: MouseEvent): void {
Text field.text = "";
}
function text1(e: MouseEvent): void {
Text field.text = "hello";
}
button_1.addEventListener(MouseEvent.MOUSE_OVER, text1);
button_1.addEventListener(MouseEvent.MOUSE_OUT, OUT);
function text2(e: MouseEvent): void {
Text field.text = "how are you doing";
}
button_2.addEventListener(MouseEvent.MOUSE_OVER, text2);
button_2.addEventListener(MouseEvent.MOUSE_OUT, OUT);
function text3(e: MouseEvent): void {
Text field.text = "WHERE DO YOU WORK?";
}
button_3.addEventListener(MouseEvent.MOUSE_OVER, text3);
button_3.addEventListener(MouseEvent.MOUSE_OUT, OUT);
function text4(e: MouseEvent): void {
Text field.text = "goodbye";
}
button_4.addEventListener(MouseEvent.MOUSE_OVER, text4);
button_4.addEventListener(MouseEvent.MOUSE_OUT, OUT);
