FiftyOneReasons

Interactive Media Development + Exploration

AS3 ToolTip Class

ActionScript 3 ToolTip

One common element of many applications is the tool tip.  Tool tips can be useful for clarifying interactions and giving more detailed descriptions of elements in an app.  Unfortunately AS3 does not have any native tool tip class so we have had to create our own.

Our goal was to make our tool tip class as easy to use as possible.  Because we use a very specific framework here at A51 our regular tool tip class is very much married to it.  So we decided to strip out any attachments to our framework and to provide it to the community.

Using the class is fairly straightforward, somewhere in your application you simply need to pass a reference of the stage to the class by calling ToolTip.init( stage );  You can then call ToolTip.show( ‘My tool tip message here’) at any point in your app.  Don’t forget to call ToolTip.hide() to make it disappear.

You can check out an example of the class in action here.   You can download this example and the class itself here.

Comments

Sebastiaan

Very nice tooltip imo, simplistic and easy to adjust. Already added a dropshadow and am currently trying to change the font to an embedded font in my swf.

Cheers!

Phil Chertok

Thanks Sebastian. We’ve got it working here with embedded fonts, just thought we’d throw it out there for people in the most simple way possible.

Ryan

Any chance od seeing a sample with embedded fonts? I’m having a bit of trouble implementing this….

Wayne Helman

We here use FlashDevelop which allows us to pull in the Flex SDK into our Flash projects. So when we compile, we actually compile with the Flex SDK as apposed to the Flash compiler. With, Flex, you can use the Embed directive like:

[Embed(source='arial.ttf', fontName = 'Arial', mimeType = 'application/x-font', unicodeRange="U+0041-U+005A")]
private var Arial:Class;

Hope that helps!

Social

Thank you for this nice Tooltip, it’s a very good base to add more stuff to, thanks!

Miguel

Great Job, just for me don’t works, I get error #1009 in ToolTip/followMouse()

Wayne Helman

Miguel, can you post the complete stack trace and which version of Flash are you using? Also, double check your compilation settings and make sure that AS3 and >= FP9 is selected.

Sonia McMAHON

Hi.
Very nice, easy to use tooltip…but for the love of God, have mercy and tell regular Flash as3 non-Flex people what they would have to do to use another font…?
Pleeeaaaase. I am new to as3.
Can u just specify a font in tooltip.as???
Help.

Sonia McMAHON

This is what I have so far in order to be able to use an embedded font…
I have added these lines to the original tooltip.as
private function initTextField():void
{
_tip = new TextField();

var myformat:TextFormat = new TextFormat();
myformat.font = “Akkurat”;
_tip.embedFonts = true;
_tip.setTextFormat(myformat);

_tip.selectable = false;
_tip.mouseEnabled = false;
//_tip.wordWrap = true;
//_tip.multiline = true;
_tip.autoSize = TextFieldAutoSize.LEFT;
_tip.border = false;
//_tip.borderColor = 0xFFFFFF;
_tip.background = true;
_tip.backgroundColor = 0×999999;
_tip.textColor = 0xFFFFFF ;

addChild(_tip);

}

Not working , I get the following error codes:
1046: Type was not found or was not a compile-time constant: TextFormat.
1180: Call to a possibly undefined method TextFormat.
Anyone?
Some help….
Thanks.

Wayne Helman

Sonia, you’ll need to add the font to your library. Then you can reference an instance of that font in your code. See here for a good walkthrough: http://tournasdimitrios1.wordpress.com/2010/09/11/using-embedded-fonts-with-the-flash-cs3-button-control/

Jovica Aleksic

Thanks a bunch for this great class. It’s the best one I’ve found for minimalist, application-style tooltips. The web is spammed with over-the-top solutions.. :)


Leave Your Mark




Feel free to use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">