读书人

flash Tooltip种

发布时间: 2012-10-15 09:45:24 作者: rapoo

flash Tooltip类
http://www.flepstudio.com/flash/actionscript3/documentation/html/com_flepstudio_text_ToolTip.html

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;????????????font=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_txt.width=field_txt.textWidth+10;????????????field_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);????????}????}}

读书人网 >Flash

热点推荐