PDA

View Full Version : How to change text in a box when hovering over a menu item?


Arteta
01-28-2009, 03:13 PM
Sorry if this isn't very clear, basically I have a menu and I would like a caption describing the menu item, it needs to change for every menu item that I hover over.

I could do this manually and include 6 descriptions saved as text and just make each appear depending on which menu item I choose, or I could make the same element appear for every button I hover over and let the actionscript generate the text dynamically. I'm guessing the latter is the preferred method these days.

Can anybody help?

Thankyou.

RelaxGuy
01-28-2009, 04:41 PM
Simple example:

var menu:Sprite = new Sprite();
var btn1:Sprite = new Sprite();
var btn2:Sprite = new Sprite();
var message:TextBox = new TextBox();

//the name property will be displayed in the textbox on hover
btn1.name = "Button1";
btn2.name = "Button2";

addChild(message);
addChild(menu);
menu.addChild(btn1);
menu.addChild(btn2);

menu.mouseEnabled = false; //so menu doesn't attempt to change the textbox text

menu.addEventListener(MouseEvent.MOUSE_OVER, updateTextBox);

//this will display either Button1 or Button2 depending on which button you mouseOver
function updateTextBox(event:MouseEvent):void
{
message.text = event.target.name;
}