July 18, 2009
Tips & Tricks 8: Actionscript 3.0 – Easy Made Tooltip
A tooltip is a brief, descriptive message that appears when you hover the mouse over an object. It is very useful and simple to create. I will create a basic one for you in Actionscript 3.0 with an “alpha” effect when you point the mouse over a movieclip.
1. Open Flash and create a new AS 3 file. (200×150)
2. Draw a rectangle(this will be our target object) and convert it to a movieclip. Give it an instance name of “mc”
3. Now we’ll create the tooltip movieclip. Draw a stroke and create a dynamic TextField. Name it “txt”. Select both and covert them to a movieclip “Tooltip”. For this one check the “Export for Actionscript” box. Delete the movieclip you just created from the stage because we’ll build an instance of it from Actionscript.
4. On the first frame of the stage, open up Actions tab and write this code:
import fl.transitions.easing.*;
import fl.transitions.*;
mc.addEventListener("mouseOver", mouseRollOver);
mc.addEventListener("mouseOut", mouseRollOut);
mc.addEventListener("mouseMove", mouseMove1);
var tooltip:Tooltip = new Tooltip();
tooltip.txt.text = "This is a tooltip";
tooltip.x = stage.mouseX;
tooltip.y = stage.mouseY - mc.height;
function mouseRollOver(e:MouseEvent):void {
addChild(tooltip);
var myTween:Tween = new Tween(tooltip, "alpha", Regular.easeIn, 0, 1, 0.5, true);
}
function mouseRollOut(e:MouseEvent):void {
removeChild(tooltip);
}
function mouseMove1(e:MouseEvent):void {
tooltip.x = stage.mouseX;
tooltip.y = stage.mouseY - mc.height;
}
5. This is how your tooltip should look like, roll over the red rectangle to see the effect. Download the file







Leave a Comment