Tooltips |
Implements tooltips for an application. Tooltips are displayed when the user hovers the mouse over associated display objects.
Tooltips | Implements tooltips for an application. |
Private constants | |
margin | Base margin constant used to position text and tooltips. |
tooltipDisplayObjectName | Display object name of a tooltip on the display list. |
Private members | |
appRoot | Reference to a sprite where tooltips and event handlers are attached. |
items | Array of registered display item name strings. |
texts | Array of tooltip text Label widgets with a one-to-one relationship with the items array for quick lookup on the same index. |
pos | Array of tooltip Point positions for custom tooltip placement. |
color | Text color used for the tooltip label texts. |
bgColor | Color of the tooltip background. |
autoRemove | Determines if tooltips are automatically removed on mouse out events. |
tip | Currently displayed tooltip sprite, null if none is shown. |
enabled | State variable determining if tooltips are displayed. |
Constructor | |
Tooltips | Creates a tooltip manager, use registerTip to add tooltips to display objects and updateTip to dynamically change and display them. |
Public methods | |
registerTip | Registers a tooltip for a display object name. |
updateTip | Update an existing tooltip and display it. |
removeTip | Removes any currently displayed tooltip from view. |
enable | Allow the tooltip manager to display tooltips. |
disable | Prevent the tooltip manager from displaying tooltips. |
Private event handlers | |
onMouseOver | Displays a tooltip when the mouse is over a display object with a name matching a registered item name and tooltips are enabled. |
onMouseOut | Removes any displayed tooltip when the mouse leaves a display object. |
Private display methods | |
displayTip | Displays a tooltip label near a display object. |
positionTip | Positions a tooltip near a display object or at a custom position. |
drawTip | Draws a tooltip background. |
addShadow | Adds a drop shadow to a tooltip sprite. |
WidgetInterface | |
active | Sets the state of the widget to active or inactive. |
activate | Activates the widget, adds its event listeners |
disactivate | Disactivates the widget, removes its event listeners |
dispose | Dispose of all resources used or referenced in the instance. |
destructor | Removes used resources, references and graphics |
private var pos: Array
Array of tooltip Point positions for custom tooltip placement. The indexed value is null, when a tooltip is automatically placed. It has a one-to-one relationship with the items array for quick lookup on the same index.
private var autoRemove: Boolean
Determines if tooltips are automatically removed on mouse out events. This is by default set to true. But setting it to false through the automaticRemove constructor parameter can avoid tooltip flicker in for instance a game where tooltips might be following moving objects. It is then up to the application to call removeTip at the appropriate times possibly in a mouse out event handler attached to the appRoot display object.
public function Tooltips( owner: String, toplevel: Sprite, frontColor: uint, backColor: uint, automaticRemove: Boolean = true ):void
Creates a tooltip manager, use registerTip to add tooltips to display objects and updateTip to dynamically change and display them.
There should only be one tooltip manager in an application or at least only one active to avoid excessive resource usage.
owner | name of registered owner; see WidgetSprite.register |
toplevel | main application or background sprite; see appRoot. |
frontColor | tooltip text color. |
backColor | tooltip background color. |
automaticRemove | whether tooltips are auto-removed (default true); see autoRemove. |
public function registerTip( itemName: String, text: String, position: Point = null ):Label
Registers a tooltip for a display object name. Can be called multiple times for the same name to change the tooltip text or position.
Normally the name of a display object is unique so each object gets its own tooltip text. However this is not required and multiple display objects can therefore all display the same tooltip.
The returned Label reference which has TextField as its base class can be used to set special text formatting properties on the tooltip label or the application may keep a reference to it to do custom tooltip text updates more efficiently than by calling this method repeatedly.
itemName | display object name used to identify when the tooltip is displayed |
text | tooltip text, can be multiline if ‘\n’ are embedded in the text |
position | custom tooltip placement (default null is automatic); see positionTip |
Reference to the created tooltip Label widget.
public function updateTip( item: DisplayObject, itemName: String, text: String, position: Point = null ):void
Update an existing tooltip and display it. Basically the same as registerTip except any displayed tooltip is removed and this tooltip is shown. The tooltip may be shown very briefly if the mouse is not over the display object where the tooltip is shown.
item | a display object where the tooltip is displayed |
itemName | display object name used to identify when the tooltip is displayed |
text | tooltip text, can be multiline if ‘\n’ are embedded in the text |
position | custom tooltip placement (default null is automatic); see positionTip |
public function enable():void
Allow the tooltip manager to display tooltips. This is by default the case. See: disable.
public function disable():void
Prevent the tooltip manager from displaying tooltips. Call enable to allow the display of tooltips again.
private function displayTip( newItem: DisplayObject, textLabel: Label ):void
Displays a tooltip label near a display object. The current implementation positions tooltips below the display object.
newItem | a new display object for which to display a tooltip |
textLabel | tooltip text label to be shown |
private function positionTip( item: DisplayObject, newTip: Sprite ):void
Positions a tooltip near a display object or at a custom position. A custom position can be given when calling registerTip or updateTip.
item | the display object for which to position the tooltip |
newTip | the tooltip background sprite to be positioned. |
private function drawTip( g: Graphics, w: Number, h: Number ):void
Draws a tooltip background. The background is drawn as a partially transparent rounded rectangle with a margin surrounding the area of the given width and height. A small rectangle is drawn to point up to a display object.
g | graphics object where the background is drawn |
w | width of the label for which the background is drawn |
h | height of the label for which the background is drawn |
Base margin constant used to position text and tooltips.
private const margin: uint
Display object name of a tooltip on the display list.
private const tooltipDisplayObjectName: String
Reference to a sprite where tooltips and event handlers are attached.
private var appRoot: Sprite
Array of registered display item name strings.
private var items: Array
Array of tooltip text Label widgets with a one-to-one relationship with the items array for quick lookup on the same index.
private var texts: Array
Array of tooltip Point positions for custom tooltip placement.
private var pos: Array
Text color used for the tooltip label texts.
private var color: uint
Color of the tooltip background.
private var bgColor: uint
Determines if tooltips are automatically removed on mouse out events.
private var autoRemove: Boolean
Currently displayed tooltip sprite, null if none is shown.
private var tip: Sprite
State variable determining if tooltips are displayed.
private var enabled: Boolean
Creates a tooltip manager, use registerTip to add tooltips to display objects and updateTip to dynamically change and display them.
public function Tooltips( owner: String, toplevel: Sprite, frontColor: uint, backColor: uint, automaticRemove: Boolean = true ):void
Registers a tooltip for a display object name.
public function registerTip( itemName: String, text: String, position: Point = null ):Label
Update an existing tooltip and display it.
public function updateTip( item: DisplayObject, itemName: String, text: String, position: Point = null ):void
Removes any currently displayed tooltip from view.
public function removeTip():void
Allow the tooltip manager to display tooltips.
public function enable():void
Prevent the tooltip manager from displaying tooltips.
public function disable():void
Displays a tooltip when the mouse is over a display object with a name matching a registered item name and tooltips are enabled.
private function onMouseOver( event: MouseEvent ):void
Removes any displayed tooltip when the mouse leaves a display object.
private function onMouseOut( event: MouseEvent ):void
Displays a tooltip label near a display object.
private function displayTip( newItem: DisplayObject, textLabel: Label ):void
Positions a tooltip near a display object or at a custom position.
private function positionTip( item: DisplayObject, newTip: Sprite ):void
Draws a tooltip background.
private function drawTip( g: Graphics, w: Number, h: Number ):void
Adds a drop shadow to a tooltip sprite.
private function addShadow( newTip: Sprite ):void
Sets the state of the widget to active or inactive.
public function set active( state: Boolean ):void
Activates the widget, adds its event listeners
private function activate():void
Disactivates the widget, removes its event listeners
private function disactivate():void
Dispose of all resources used or referenced in the instance.
public function dispose():void
Removes used resources, references and graphics
private function destructor():void
Register the owner of a widget.
public function register( owner: String ):void