Tips & Tricks 8: Actionscript 3.0 – Easy Made Tooltip July 18, 2009

Tips & Tricks 8: Actionscript 3.0 – Easy Made Tooltip

by flashuser in ActionScript 3.0, Flash Tips & Tricks

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

Subscribe to our RSS Feed and follow us on Twitter

Enjoy this post?

Help us grow this site and share the content with others among you.

img-delicious img-digg img-twitter
img-stumbleupon img-facebook img-mixx

Leave a Comment

Note: You can get a Gravatar account for free so your avatar can be shown when you post a comment on any website that supports gravatars.