Return to Snippet

Revision: 34909
at October 30, 2010 06:46 by manuletroll


Updated Code
package ariane.ui
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize ;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign ;
	import caurina.transitions.Tweener ;
	/**
	 * Classe permettant l'usage d'un objet graphique en gros similaire au paramètre "title" d'une image en html.
	 * @author Manu
	 */
	public class Tooltip extends Sprite
	{
		protected var _bgColor:Number ;
		protected var _txtColor:Number ;
		protected var _txtF:TextField ;
		protected var _stageRef:Stage ;
		protected var _box:Sprite ;
		protected var _format:TextFormat ;
		
		/**
		 * 
		 * @param	s Référence à la scène principale
		 * @param	bgcolor Couleur de fond du tooltip
		 * @param	txtcolor Couleur du texte
		 * @param	font Police utilisée : à choisir parmi les polices web classiques pour éviter l'incorporation
		 * @param	fontSize Taille de police
		 */
		public function Tooltip(s:Stage, bgcolor:Number, txtcolor:Number, font:String="Verdana", fontSize:int=10) 
		{
			
			this.alpha = 0 ;
			this.mouseEnabled = false ;
			
			_stageRef = s ;
			_bgColor = bgcolor ;
			_txtColor = txtcolor ;
			
				
			_box = new Sprite() ;
				_box.graphics.beginFill(_bgColor) ;
				_box.graphics.lineStyle(2) ;
				_box.graphics.drawRect(0, 0, 100, 20) ;
				_box.graphics.endFill() ;
				this.addChild(_box) ;
			
			_format = new TextFormat() ;
				_format.font = font ;
				_format.size = fontSize ;
				_format.align = TextFormatAlign.LEFT ;
				_format.color = _txtColor ;
			
		}
		
		/**
		 * Méthode à appeler pour faire apparaître le tooltip
		 * @param	text Texte à afficher
		 */
		public function show(text:String ):void
		{
			this.x = _stageRef.mouseX + 5 ;
			this.y = _stageRef.mouseY + 5 ;
			
			_txtF = new TextField() ;
			_txtF.defaultTextFormat = _format ;
			
			_txtF.y = 2 ;
			_txtF.autoSize = TextFieldAutoSize.RIGHT ;
			_txtF.text = text
			_txtF.x = _box.x ;
			
			this.addChild(_txtF) ;
			_box.height = _txtF.height + 2 ;
			_box.width = _txtF.width + 5 ;
			Tweener.addTween(this, {time:0.25, alpha:1, transition:"linear" } ) ;
			this.addEventListener(Event.ENTER_FRAME, move) ;
		}
		
		/**
		 * Méthode permettant au tooltip de suivre le mouvement de la souris
		 * @param	e
		 */
		protected function move(e:Event):void
		{
			this.x = _stageRef.mouseX + 10;
			this.y = _stageRef.mouseY + 10;
		}
		
		/**
		 * Cache le tooltip et détruit le champ de texte
		 */
		public function hide():void
		{
			this.alpha = 0 ;
			Tweener.addTween(this, { alpha:0, delay:0.05 } );
			this.removeChild(_txtF) ;
		}
		
	}

}

Revision: 34908
at October 30, 2010 02:27 by manuletroll


Initial Code
package manuletroll.ui
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize ;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign ;
	import caurina.transitions.Tweener ;
	/**
	 * Classe permettant l'usage d'un objet graphique en gros similaire au paramètre "title" d'une image en html.
	 * @author Manu
	 */
	public class Tooltip extends Sprite
	{
		protected var _bgColor:Number ;
		protected var _txtColor:Number ;
		protected var _txtF:TextField ;
		protected var _stageRef:Stage ;
		protected var _box:Sprite ;
		protected var _format:TextFormat ;
		
		public function Tooltip(s:Stage, bgcolor:Number, txtcolor:Number, font:String="Verdana", fontSize:int=10) 
		{
			
			this.alpha = 0 ;
			this.mouseEnabled = false ;
			
			_stageRef = s ;
			_bgColor = bgcolor ;
			_txtColor = txtcolor ;
			
				
			_box = new Sprite() ;
				_box.graphics.beginFill(_bgColor) ;
				_box.graphics.lineStyle(2) ;
				_box.graphics.drawRect(0, 0, 100, 20) ;
				_box.graphics.endFill() ;
				this.addChild(_box) ;
			
			_format = new TextFormat() ;
				_format.font = font ;
				_format.size = fontSize ;
				_format.align = TextFormatAlign.LEFT ;
				_format.color = _txtColor ;
			
		}
		
		public function show(text:String ):void
		{
			this.x = _stageRef.mouseX + 5 ;
			this.y = _stageRef.mouseY + 5 ;
			
			_txtF = new TextField() ;
			_txtF.defaultTextFormat = _format ;
			
			_txtF.y = 2 ;
			_txtF.autoSize = TextFieldAutoSize.RIGHT ;
			_txtF.text = text
			_txtF.x = _box.x ;
			
			this.addChild(_txtF) ;
			_box.height = _txtF.height + 2 ;
			_box.width = _txtF.width + 5 ;
			Tweener.addTween(this, {time:0.25, alpha:1, transition:"linear" } ) ;
			this.addEventListener(Event.ENTER_FRAME, move) ;
		}
		
		protected function move(e:Event):void
		{
			this.x = _stageRef.mouseX + 10;
			this.y = _stageRef.mouseY + 10;
		}
		
		public function hide():void
		{
			this.alpha = 0 ;
			Tweener.addTween(this, { alpha:0, delay:0.05 } );
			this.removeChild(_txtF) ;
		}
		
	}

}

Initial URL


Initial Description


Initial Title
Quick & Dirty Tooltip Class

Initial Tags
class

Initial Language
ActionScript 3