写了一个用来实现当鼠标滑过时出现提示信息的Tip类.
可以动态改变目标MC以及其他的相关属性,并且可以控制Tip运行还是不运行.主要通过Run()和StopRun()两个方法,在构造函数中可以选择是否自动调用Run()方法,而在改变了目标MC或者改变了了一些属性时,则需要调用ReRun()方法来使改变生效。
具体实现代码如下:
/***********************************************************************************
Author : Tomato
Mail : SuperTomato@sjtu.edu.cn
Blog : http://blog.csdn.net/crazytomato
***********************************************************************************/
class Tip{
public var tipText:String;
public var tipWidth:Number;
public var tipHeight:Number;
public var textFormat:TextFormat;
public var tipTextColor:Number;
public var tipBorderColor:Number;
public var bgColor:Number;
public var targetMovie:MovieClip;
public function changeTarget(_newTarget:MovieClip){StopRun();
targetMovie = _newTarget;
Run();
}
private var _autoSize:String;
public function get autoResize():Boolean{
if(_autoSize == "none"){
return false;
}else{
return true;
}
}
public function set autoResize(_bool:Boolean){
if(_bool == true){
_autoSize = "left";
}else{
_autoSize = "none";
}
}
//save the interface to control the internal TextField
private var _textField:TextField;
public function get internalTextField():TextField{
return _textField;
}
public function Tip(_targetMovie:MovieClip , _tipText:String , _autoRun:Boolean){
targetMovie = _targetMovie;
tipText = _tipText;
tipWidth = 200;
tipHeight = 20;
_autoSize = "left";
tipTextColor = 0x000000;
tipBorderColor = 0x000000;
bgColor = 0xFFFFE1;
_textField = null;
if(_autoRun == true){
Run();
}
}
public function Run():Void{
var tipObj = this;
targetMovie.onRollOver = function(){
_root.createEmptyMovieClip("tempMC" , _root.getNextHighestDepth());
_root.tempMC.createTextField("tipLoader" , _root.getNextHighestDepth() , _root._xmouse , _root._ymouse , tipWidth , tipHeight);
with(_root.tempMC.tipLoader){
selectable = false;
text = tipObj.tipText;
background = true;
border = true;
autoSize = tipObj._autoSize;
textColor = tipObj.tipTextColor;
borderColor = tipObj.tipBorderColor;
backgroundColor = tipObj.bgColor;
}
if((tipObj.textFormat != null) && (tipObj.textFormat != undefined)){
_root.tempMC.tipLoader.setTextFormat(textFormat);
}
tipObj._textField = _root.tempMC.tipLoader;
}
targetMovie.onRollOut = function(){
tipObj._textField.removeTextField();
_root.tempMC.tipLoader.removeTextField();
_root.tempMC.removeMovieClip();
}
targetMovie.onPress = function(){
tipObj._textField.removeTextField();
_root.tempMC.tipLoader.removeTextField();
_root.tempMC.removeMovieClip();
}
targetMovie.onReleaseOutside = function(){
tipObj._textField.removeTextField();
_root.tempMC.tipLoader.removeTextField();
_root.tempMC.removeMovieClip();
}
}
public function StopRun():Void{
delete targetMovie.onRollOver;
delete targetMovie.onRollOut;
delete targetMovie.onPress;
delete targetMovie.onReleaseOutside;
}
public function ReRun():Void{
StopRun();
Run();
}
}
写了一个Tip类(AS)
最新推荐文章于 2021-11-05 02:09:01 发布