[AS3]as3.0的Tooltip类示例
[AS3]as3.0的Tooltip类示例
[AS3]as3.0的Tooltip类示例
- package com.flepstudio.text
- {
- import flash.display.*;
- import flash.events.*;
- import flash.text.*;
- /**
- * ToolTip is a ValueObject for the FlepStudio API.
- * This class produces a tooltip advice on mouse rollover
- *
- * @author Filippo Lughi
- * @version Actionscript 3.0
- */
- public class ToolTip extends MovieClip
- {
- private var _bg_color:uint;
- private var _text_color:uint;
- private var _text_size:int;
- private var _font:String;
- private var _tool_text:String;
- private var _field_txt:TextField;
- private var _alpha_color:Number;
- private var ratio:int=10;
- private var holder_mc:MovieClip;
- private var bg_mc:MovieClip;
- private var father:MovieClip;
- /**
- * Construct a new ToolTip instance
- *
- * @param .bc uint -- background color
- * @param .tc uint -- text color
- * @param .ts int -- text size
- * @param .f String -- the font to use
- * @param .tt String -- text of the tooltip
- * @param .n Number -- alpha of background color
- */
- public function ToolTip(bc:uint,tc:uint,ts:int,f:String,tt:String,n:Number)
- {
- bg_color=bc;
- text_color=tc;
- text_size=ts;
- ffont=f;
- tool_text=tt;
- alpha_color=n;
- addEventListener(Event.ADDED_TO_STAGE,init);
- mouseEnabled=false;
- alpha=0;
- }
- /**
- * Background color
- */
- public function get bg_color():uint
- {
- return _bg_color;
- }
- public function set bg_color(c:uint):void
- {
- _bg_color=c;
- }
- /**
- * Text color
- */
- public function get text_color():uint
- {
- return _text_color;
- }
- public function set text_color(c:uint):void
- {
- _text_color=c;
- }
- /**
- * Text size
- */
- public function get text_size():int
- {
- return _text_size;
- }
- public function set text_size(n:int):void
- {
- _text_size=n;
- }
- /**
- * The font
- */
- public function get font():String
- {
- return _font;
- }
- public function set font(s:String):void
- {
- _font=s;
- }
- /**
- * The text
- */
- public function get tool_text():String
- {
- return _tool_text;
- }
- public function set tool_text(s:String):void
- {
- _tool_text=s;
- }
- /**
- * The text
- */
- public function get field_txt():TextField
- {
- return _field_txt;
- }
- public function set field_txt(t:TextField):void
- {
- _field_txt=t;
- }
- /**
- * The alpha color
- */
- public function get alpha_color():Number
- {
- return _alpha_color;
- }
- public function set alpha_color(n:Number):void
- {
- _alpha_color=n;
- }
- /**
- * Init the class
- *
- * @param .evt Event
- */
- private function init(evt:Event):void
- {
- removeEventListener(Event.ADDED_TO_STAGE,init);
- father=parent as MovieClip;
- createHolder();
- createTextField();
- createBackground();
- fixPosition();
- fadeIn();
- addEventListener(Event.ENTER_FRAME,addMovement);
- }
- /**
- * Container MovieClip creation
- *
- */
- private function createHolder():void
- {
- holder_mc=new MovieClip();
- addChild(holder_mc);
- }
- /**
- * TextField tooltip creation
- *
- */
- private function createTextField():void
- {
- field_txt=new TextField();
- field_txt.multiline=true;
- field_txt.selectable=false;
- field_txt.embedFonts=true;
- field_txt.antiAliasType=AntiAliasType.ADVANCED;
- field_txt.autoSize=TextFieldAutoSize.LEFT;
- field_txt.defaultTextFormat=getFormat();
- field_txt.htmlText=tool_text+" ";
- field_txtfield_txt.width=field_txt.textWidth+10;
- field_txtfield_txt.height=field_txt.textHeight+20;
- holder_mc.addChild(field_txt);
- }
- /**
- * Get a text format
- *
- * @return
TextFormat
the textfield's format of tooltip- */
- private function getFormat():TextFormat
- {
- var format:TextFormat=new TextFormat();
- format.font=font;
- format.size=text_size;
- format.color=text_color;
- return format;
- }
- /**
- * Background MovieClip creation
- *
- */
- private function createBackground():void
- {
- bg_mc=new MovieClip();
- bg_mc.graphics.beginFill(bg_color,alpha_color);
- bg_mc.graphics.drawRoundRect(-ratio,-ratio,field_txt
.width+ratio*2,field_txt.height+ratio*2,ratio,ratio);- holder_mc.addChild(bg_mc);
- holder_mc.swapChildren(field_txt,bg_mc);
- }
- /**
- * Position the tooltip
- *
- */
- private function fixPosition():void
- {
- if(father.mouseX < stage.stageWidth/2)
- x=father.mouseX;
- else
- x=father.mouseX-width;
- if(father.mouseY < stage.stageHeight/2)
- y=father.mouseY+height-ratio*2;
- else
- y=father.mouseY-height;
- }
- /**
- * Init fade-in section of tooltip
- *
- */
- private function fadeIn():void
- {
- bg_mc.addEventListener(Event.ENTER_FRAME,fadeInToolTip);
- }
- /**
- * Fade-in of tooltip
- *
- * @param .evt Event
- */
- private function fadeInToolTip(evt:Event):void
- {
- var distance:Number=1-alpha;
- var inertial:Number=distance*.2;
- alpha+=inertial;
- if(Math.abs(distance) <= .1)
- {
- alpha=1;
- bg_mc.removeEventListener(Event.ENTER_FRAME,fadeInToolTip);
- }
- }
- /**
- * Movement of tooltip
- *
- * @param .evt Event
- */
- private function addMovement(evt:Event):void
- {
- if(father.mouseX < stage.stageWidth/2)
- x=father.mouseX;
- else
- x=father.mouseX-width+ratio*2;
- if(father.mouseY < stage.stageHeight/2)
- y=father.mouseY+height-ratio*2;
- else
- y=father.mouseY-height;
- if(x > stage.stageWidth-width)
- x=stage.stageWidth-width;
- if(x < ratio*2)
- x=ratio*2;
- }
- /**
- * Remove this instance
- *
- */
- public function destroy():void
- {
- removeEventListener(Event.ENTER_FRAME,addMovement);
- bg_mc.removeEventListener(Event.ENTER_FRAME,fadeInToolTip);
- father.removeChild(this);
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...