042009
 

因为TextField不支持对alpha的变换。因此需要对其进行一些操作。

有两种方法。

第一是使用BitmapData去绘制,然后对Bitmap进行操作,这个方法代码量稍微偏多,这里不做赘述。

第二种是使用ColorMatrixFilter过滤器。

//Code:
package com.drore.map.view
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.filters.ColorMatrixFilter;
	
	/**
	 * 动态生成鼠标提示
	 * @author Dada http://www.isdada.com
	 * @version 5.0
	 * @copy Drore http://www.drore.com
	 */
	public class MouseTip extends Sprite
	{
		private var txtTips:TextField = new TextField();
		public function MouseTip() 
		{
			addEventListener(Event.ENTER_FRAME, init);
		}
		
		private function init(event:Event):void
		{
			removeEventListener(Event.ENTER_FRAME, init);
			txtTips.selectable = false;
			txtTips.tabEnabled = false;
			txtTips.mouseEnabled = false;
			txtTips.cacheAsBitmap = true;
			txtTips.multiline = false;
			//设置滤镜
			txtTips.filters=[new ColorMatrixFilter];
			addChild(txtTips);
		}
		//设置提示文字
		public function setText(txt:String):void
		{
			txtTips.text = txt;
			txtTips.width = txtTips.textWidth + 10;
			drawBg();
		}
		//绘制背景
		private function drawBg():void
		{
			graphics.clear();
			graphics.beginFill(0xF3E789, .8);
			graphics.lineStyle(1, 0xFFFF00);
			graphics.drawRoundRect( -5, -5, txtTips.textWidth + 15, txtTips.textHeight + 15, 10, 10);
			graphics.endFill();
		}
	}
	
}

使用方法:

//Code:
//鼠标提示框
private var mtips:MouseTip = new MouseTip();
mtips.setText("This is a test sentense.");
//使用TweenLite对mtips进行alipa缓动
TweenLite.to(mtips, .3, { alpha:0 } );

  3 Responses to “ActionScript中文本字段的透明度缓动”

  1. 一上班就更新,果然是好孩子,哈哈
    新年快乐

  2. @Sshong:
    哈哈, 新年快乐,牛牛牛气!

  3. 好东西,谢谢

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>