codice:
/**
* Class ToolTip :: ToolTip.as :: by [ andr3a ]
* Create one or more tooltips for your MovieClips, Buttons and other object
* without modify or implement Button's statements such onPress, OnRelease
* or other events.
* .
* EXAMPLE:
* var myTT:ToolTip = new ToolTip( this, 30, 0x000000, 0xFAFADB, 0x000000 );
* myTT.setFont( "myAliasLinkage", 10, true );
* myTT.setLabel( testMovie1, "my label" );
* myTT.setLabel( testMovie2, "mytest2" );
*
* @version ActionScript 2.0 class file
* @author Andrea Giammarchi
* @date 05/01/2004
* @lastMod 17/02/2004 02:50
* @site http://www.3site.it/
*/
class ToolTip {
private var TT_textFormat:TextFormat;
private var TT_graphic:Object;
private var TT_absolutePath:Object;
private var TT_embed:Boolean;
private var TT_fontColor:Number, TT_borderColor:Number, TT_backgroundColor:Number, TT_showCounter:Number;
/**
* Public constructor
* var myToolTip:ToolTip = new ToolTip( path [ latency, [ fontColor, [ backgroundColor, [ borderColor ]]]] );
*
* @param Object path where tooltip will be created
* Example: _root, this, MovieClip, etc.
* @param Number latency before show ToolTip( 0 - 100 ) DEFAULT: 0
* @param Number font color ( DEFAULT: 0x000000 )
* @param Number background color
* @param Number border color
*/
function ToolTip( TT_absolutePath:Object, TT_showCounter:Number, TT_fontColor:Number, TT_backgroundColor:Number, TT_borderColor:Number ) {
this.TT_absolutePath = TT_absolutePath;
this.TT_fontColor = TT_fontColor;
this.TT_borderColor = TT_borderColor;
this.TT_backgroundColor = TT_backgroundColor;
this.TT_showCounter = Math.abs( TT_showCounter );
TT_embed = new Boolean( false );
TT_textFormat = new TextFormat();
TT_textFormat.font = "Verdana";
TT_textFormat.size = 10;
TT_textFormat.leftMargin = 2;
TT_textFormat.rightMargin = 2;
var maxDepht:Number = new Number( TT_absolutePath.getNextHighestDepth() );
var remName:String = new String( "TT_object_" + maxDepht );
TT_absolutePath.createEmptyMovieClip( remName, maxDepht );
TT_graphic = new Object( _root[remName] );
TT_graphic.createTextField( "TT_label" , TT_absolutePath.getNextHighestDepth() , 0 , 0 , 1 , 1 );
labelSetup( TT_graphic["TT_label"], TT_fontColor, TT_backgroundColor, TT_borderColor );
TT_graphic._visible = false;
}
/**
* Public method
* myToolTip.setLabel( TT_movie:Object, TT_label:String );
*
* @param Object MovieClip, Button or other to apply ToolTip
* @param String String to show on ToolTip
* @return Void
*/
public function setLabel( TT_movie:Object, TT_label:String ):Void {
var maxDepht:Number = new Number( TT_absolutePath.getNextHighestDepth() );
var remName:String = new String( "TT_object_" + maxDepht );
TT_graphic.duplicateMovieClip( remName, maxDepht );
TT_absolutePath[remName].createTextField( "TT_label" , TT_absolutePath.getNextHighestDepth() , 0 , 0 , 1 , 1 );
labelSetup( TT_absolutePath[remName]["TT_label"], TT_fontColor, TT_backgroundColor, TT_borderColor );
TT_absolutePath[remName].TT_label.htmlText = TT_label + " ";
TT_absolutePath[remName].TT_label.setTextFormat( TT_textFormat );
TT_absolutePath[remName]._alpha = 0;
TT_absolutePath[remName].__ToolTipInterval = setInterval( this.manageLabel, 20, TT_movie, TT_absolutePath[remName], TT_absolutePath, TT_showCounter );
}
/**
* Public method
* myToolTip.setFont( TT_textFormat:String[, TT_fontsize:Number[, TT_embed:Boolean ]] );
*
* @param String font's linkage or font name
* @param Number font size ( DEFAULT: default flash choice )
* @param Boolean embedFont ( DEFAULT: false )
* @return Void
*/
public function setFont( TT_textFormat:String, TT_fontsize:Number, TT_embed:Boolean ):Void {
this.TT_textFormat.font = TT_textFormat;
if( TT_fontsize != undefined ) {
this.TT_textFormat.size = TT_fontsize;
}
if( TT_embed == true ) {
this.TT_embed = true;
}
else {
this.TT_embed = false;
}
TT_graphic.TT_label.setTextFormat( this.TT_textFormat );
}
private function labelSetup( myLabel:Object, TT_fontColor:Number, TT_backgroundColor:Number, TT_borderColor:Number ):Void {
if( TT_fontColor == undefined ) {
TT_fontColor = 0x000000;
}
if( TT_backgroundColor != undefined ) {
myLabel.background = true;
myLabel.backgroundColor = TT_backgroundColor;
}
if( TT_borderColor != undefined ) {
myLabel.border = true;
myLabel.borderColor = TT_borderColor;
}
myLabel.autoSize = true;
myLabel.multiline = true;
myLabel.selectable = false;
myLabel.textColor = TT_fontColor;
myLabel.embedFonts = TT_embed;
}
private function manageLabel( TT_movie:Object, TT_graphic:Object, TT_absolutePath:Object, TT_showCounter:Number ):Void {
if( TT_movie.hitTest( _root._xmouse, _root._ymouse ) ) {
var maxDepth:Number = new Number( TT_absolutePath.getNextHighestDepth() );
if( TT_graphic.getDepth() != ( maxDepth - 1 ) ) {
TT_graphic.swapDepths( ( maxDepth - 1 ) );
}
if( TT_graphic.restarted == TT_showCounter ) {
if( TT_graphic._visible == false ) {
TT_graphic._visible = true;
}
if( TT_graphic._alpha < 100 ) {
TT_graphic._alpha += 10;
}
else if( TT_graphic._alpha != 100 ){
TT_graphic._alpha = 100;
}
}
else {
if( TT_graphic.restarted == undefined ) {
TT_graphic.restarted = 0;
}
TT_graphic.restarted++;
}
var maxWidth:Number = new Number( _root._xmouse + 20 + TT_graphic._width );
var maxHeight:Number = new Number( _root._ymouse + 20 + TT_graphic._height );
if( ( maxWidth > Stage.width ) || ( maxHeight > Stage.height ) ) {
if( maxWidth > Stage.width && maxHeight > Stage.height ) {
TT_graphic._x = Stage.width - TT_graphic._width;
TT_graphic._y = Stage.height - TT_graphic._height;
}
else if( maxWidth > Stage.width && maxHeight < Stage.height ) {
TT_graphic._x = Stage.width - TT_graphic._width;
TT_graphic._y = _root._ymouse + 20;
}
else if( maxWidth < Stage.width && maxHeight > Stage.height ) {
TT_graphic._y = Stage.height - TT_graphic._height;
TT_graphic._x = _root._xmouse + 20;
}
}
else {
TT_graphic._x = _root._xmouse + 20;
TT_graphic._y = _root._ymouse + 20;
}
}
else {
if( TT_graphic._alpha <= 0 ) {
if( TT_graphic._visible == true ) {
TT_graphic._visible = false;
TT_graphic._alpha = 0;
TT_graphic.restarted = 0;
}
}
else {
TT_graphic._alpha -= 10;
}
}
}
}
Pareri, critiche e consigli sono bene accetti