【www.gdgbn.com--Action】

 

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

第二种是使用ColorMatrixFilter过滤器。

//Code:
  1. package com.drore.map.view
  2. {
  3.  import flash.display.Sprite;
  4.  import flash.events.Event;
  5.  import flash.text.TextField;
  6.  import flash.filters.ColorMatrixFilter;
  7.  
  8.  /**
  9.   * 动态生成鼠标提示
  10.   * @author Dada http://www.asflex.cn
  11.   * @version 5.0
  12.   * @copy Drore http://www.drore.com
  13.   */
  14.  public class MouseTip extends Sprite
  15.  {
  16.   private var txtTips:TextField = new TextField();
  17.   public function MouseTip()
  18.   {
  19.    addEventListener(Event.ENTER_FRAME, init);
  20.   }
  21.  
  22.   private function init(event:Event):void
  23.   {
  24.    removeEventListener(Event.ENTER_FRAME, init);
  25.    txtTips.selectable = false;
  26.    txtTips.tabEnabled = false;
  27.    txtTips.mouseEnabled = false;
  28.    txtTips.cacheAsBitmap = true;
  29.    txtTips.multiline = false;
  30.    //设置滤镜
  31.    txtTips.filters=[new ColorMatrixFilter];
  32.    addChild(txtTips);
  33.   }
  34.   //设置提示文字
  35.   public function setText(txt:String):void
  36.   {
  37.    txtTips.text = txt;
  38.    txtTips.width = txtTips.textWidth + 10;
  39.    drawBg();
  40.   }
  41.   //绘制背景
  42.   private function drawBg():void
  43.   {
  44.    graphics.clear();
  45.    graphics.beginFill(0xF3E789, .8);
  46.    graphics.lineStyle(1, 0xFFFF00);
  47.    graphics.drawRoundRect( -5, -5, txtTips.textWidth + 15, txtTips.textHeight + 15, 10, 10);
  48.    graphics.endFill();
  49.   }
  50.  }
  51.  
  52. }

使用方法:

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

本文来源:http://www.gdgbn.com/flash/18785/