1

I'm trying to create one of my first actionscript3s...I want to make a dynamic text box (dynText) write a description of what the hovered button (stopButton) does.

No text is shown when I hover the button and I get no error message. Why?

This is my code

dynText.addEventListener( MouseEvent.MOUSE_OVER, myInfoHandler )
function myInfoHandler( event ){
    if(event.target.name == "stopButton"){
    dynText.text = "Stop animation!";
    }
}

And just to make sure it isn't the text fields fault: to make a dynamic text field do I just create a text field and choose "Dynamic text" in the dropodown?

I've tried too google and read other answers but I guess I'm too much of a noob to understand...

  • have you tried dynText.buttonMode = true; dynText.mouseChildren = false; – The_asMan Feb 28 '13 at 18:34
  • Have you added your textfield as a child? Like `addChild(dynText);`. May be you do not see it because it is not added. – sybear Feb 28 '13 at 18:37
  • No I haven't tried any of that. Where should I put it? Before the rest of the code or...? – guldarmband Feb 28 '13 at 18:42
  • @Jari tried putting addChild(dynText); before the rest of the code but it makes no difference. – guldarmband Feb 28 '13 at 18:55
  • @The_asMan I don't get where to put the code you recommended? – guldarmband Feb 28 '13 at 18:59
  • If I understand it correctly, you have a stop button and want to show a text (like a tooltip) when that is hovered. If so, you should add the event listener to the button, not to the text box. So like stopButton(MouseEvent.MOUSE_OVER, myInfoHandler) instead of dynText.addEventListener(MouseEvent.MOUSE_OVER, myInfoHandler). – Lars Blåsjö Feb 28 '13 at 20:00
  • @LarsBlåsjö YES! It works! Tack så hemskt mycket! :D – guldarmband Feb 28 '13 at 20:05

1 Answers1

2

Try changing this line:

dynText.addEventListener(MouseEvent.MOUSE_OVER, myInfoHandler);

to this:

stopButton.addEventListener(MouseEvent.MOUSE_OVER, myInfoHandler);

You want the listener to trigger when the button is moused over, not the text field, so you need to add the listener to the button itself.

Alexis King
  • 43,109
  • 15
  • 131
  • 205