Access keys

Tooltip

Kind of class: class
Inherits from: none
Author: Arthur Clemens
Classpath: org.asapframework.ui.Tooltip
File last modified: Wednesday, 11 October 2006, 21:52:46
Tooltip class.
Usage:
You can customize a Tooltip by either setting properties after creation, or by creating a Tooltip subclass (see further below).

The following code creates a new tooltip:
var tip:Tooltip = new Tooltip("tip", _level0, 9999, "Click to enlarge");
tip.create();
tip.setLoc(new Point(100,100));
Change the tooltip properties:
tip.backgroundColor = 0x990000;
tip.textColor = 0xffffff;
tip.textSize = 15;
tip.borderWidth = 0; // no border
Set a new text:
tip.setText("Click to go back");
After (dynamically) setting Tooltip properties, update must be called:
tip.update();

To use embedded fonts in the Tooltip, the font should be available in the Flash movie - for instance by placing a dynamic text field with that font embedded offscreen. If you want to use "Monaco" for instance, write:
tip.fontName = "Monaco";
tip.textField.embedFonts = true;
tip.update();

To use multiple lines, word wrap, set:
tip.textField.wordWrap = true;

You can also create a Tooltip subclass. For example:
//import flash.geom.*;
// Still support Flash 7:
import org.asapframework.util.types.*;

import org.asapframework.ui.Tooltip;

class MCTooltip extends Tooltip {

    public function MCTooltip (inName:String, inTimeline:MovieClip, inDepth:Number, inText:String) {
        super(inName, inTimeline, inDepth, inText);
        // set custom properties
        backgroundColor = 0xffffff;
        borderAlpha = 20;
        fontName = "DIN-Light";
        textSize = 12;
        offset = new Point(2, -1);
        padding = new Point(2, 2);
        minWidth = 1;
        maxWidth = 200;
        // create clips
        create();
        textField.embedFonts = true;
        // set invisible to make it appear only on rollover the right spot
        clip._visible = false;
    }

}
To do:
Fix unwanted wrapping with wordWrap true.

Constructor

Tooltip

function Tooltip (
inName:String, inTimeline:MovieClip, inDepth:Number, inText:String)
Creates a new Tooltip and optionally sets properties. Will not draw the clip: always call create to create the Tooltip movieclip parts.
Parameters:
inName :
(optional) name of Tooltip movieclip on timeline inTimeline
inTimeline:
(optional) timeline of Tooltip movieclip
inDepth :
(optional) stack depth of Tooltip movieclip
inText :
(optional) Tooltip text contents; may contain html formatting

Instance properties

backgroundAlpha

backgroundAlpha:Number = 100
(read,write)
Alpha blend of background.

backgroundClip

backgroundClip:MovieClip
(read,write)
Background movieclip. The background color is a box that is drawn onto the background clip.

backgroundColor

backgroundColor:Number = 0xFEF49C
(read,write)
Background color; default light yellow.

borderAlpha

borderAlpha:Number = 50
(read,write)
Alpha blend of border.

borderColor

borderColor:Number = 0x8D7F01
(read,write)
Border color.

borderWidth

borderWidth:Number = 1
(read,write)
Width of box border. Use 0 for no border.

clip

clip:MovieClip
(read,write)
The Tooltip movieclip and holder of subclips backgroundClip and textField.

fontName

fontName:String = "Arial"
(read,write)
Font name. By default the font is not embedded - use myTip.textField.embedFonts = true;

maxWidth

maxWidth:Number = 150
(read,write)
The minimum width of the tooltip; more text will be displayed on multiple lines.

minWidth

minWidth:Number = 50
(read,write)
The minimum width of the tooltip, regardless the amount of text.

offset

offset:Point
(read,write)
The box offset position from the tip _x and _y position; default (0,0).

padding

padding:Point
(read,write)
The inside spacing between text and border. Default (1,0).

textColor

textColor:Number = 0x000000
(read,write)
Color of text.

textField

textField:TextField
(read,write)
Text container.

textFormat

textFormat:TextFormat
(read,write)
TextFormat object of textField.

textSize

textSize:Number = 11
(read,write)
Size of text.

Instance methods

create

function create (
) : Void
Creates the movieclip parts if they do not exist yet: the Tooltip clip, the background clip and the textfield. Sets default textfield properties.

die

function die (
) : Void
Removes the Tooltip clip parts and calls delete on itself.

setLoc

function setLoc (
inLoc:Point) : Void
Sets the position of the Tooltip.
Parameters:
inLoc:
the new position relative of the Tooltip movieclip

setText

function setText (
inText:String) : Void
Sets a new Tooltip text and redraws.
Parameters:
inText:
text contents; may contain html formatting
Implementation note:
Calls update

toString

function toString (
) : String

update

function update (
) : Void
Updates and redraws the movieclip. Call this function after setting properties.