ForumsProgramming ForumButton description assistance

3 2575
sidheman
offline
sidheman
3 posts
Peasant

I've got by buttons all programmed and everything, but I'm having a hard time adding what I want to them. What I would like to have happen, is when someone mouses over the button, a bit of descriptor text pops up in a text box (or somewhere on the stage), then pops back off when the mouse is no longer there, so that another button's description can show up.

I know how to do this the long way, by making several text boxes with the description written, changing the Alpha to 0, adding action script to it for when the mouse is over the button to make it Alpha 100%, but that seems like a bit too much to have to go through for such a simple thing. Is there an easier - or rather a more effective way to do it with AS3?

  • 3 Replies
Erasmus_Darwin
offline
Erasmus_Darwin
59 posts
Nomad

Just encapsulate the tooltip behavior in its own class. That way you only have to write the tooltip code once, and it'll handle the mouseover detection and textfield creation.

sidheman
offline
sidheman
3 posts
Peasant

Sweet, thanks! I thought it was something like that, just wasn't sure.

joeybetz
offline
joeybetz
107 posts
Shepherd

Another way is to create the textfield on the stage and give it an instance name. Then add a Roll Over and Roll Out event to each button, and in the roll over code replace the text in the text field with what ever you want. An easy way to do this is to initialize each button with a dynamic instance variable (a variable/member created during run-time) that contains the text you want to display.

Example:

myButton_mc.tooltipTxt = "This is a tool tip";

function handleRollOver(e:MouseEvent):void
{
tooltip_txt.text = e.currentTarget.tooltipTxt;
}

function handleRollOut(e:MouseEvent):void
{
tooltip_txt.text = "";
}

Showing 1-3 of 3