第一是使用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.asflex.cn
- * @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 } );
时间: 2024-11-03 13:30:35