当前位置: 首页 > 图文教程 > Flash动画 > ActionScript > Flash AS文本字段的透明度alpha变换

ActionScript
Flash AS教程:图片环绕旋转动画
Flash贪吃蛇游戏AS代码翻译
Flash AS教程:旋转立方体
Flash AS3教程:ImageLoader类
Flash AS3教程:疑难杂症汇总
Flash AS3教程:类的分包处理
Flash AS3教程:Dot类
Flash游戏开发:BitmapData的使用
初学AS3的几点技巧汇总
飘雪Flash动画简单制作
Flash air制作淡入淡出窗体动画效果
Flash air制作透明雪花特效
Flash AS制作LRC歌词同步的详细教程
Flash as3:绝对坐标与相对坐标
Flash AS3用于读取LRC同步歌词的类
优化Flash Actionscript代码的三种方法
AS3的System类解决歌词中乱码问题
Flash as3嵌入中文字体的方法
Flash AS3教程:ClassLoader类
Flash AS3教程:ByteLoader类

ActionScript 中的 Flash AS文本字段的透明度alpha变换


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-30   浏览: 220 ::
收藏到网摘: n/a

因为TextField不支持对alpha的变换,因此需要对其进行一些操作,有两种方法:

第一是使用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.   private function init(event:Event):void
  22.   {
  23.    removeEventListener(Event.ENTER_FRAME, init);
  24.    txtTips.selectable = false;
  25.    txtTips.tabEnabled = false;
  26.    txtTips.mouseEnabled = false;
  27.    txtTips.cacheAsBitmap = true;
  28.    txtTips.multiline = false;
  29.    //设置滤镜
  30.    txtTips.filters=[new ColorMatrixFilter];
  31.    addChild(txtTips);
  32.   }
  33.   //设置提示文字
  34.   public function setText(txt:String):void
  35.   {
  36.    txtTips.text = txt;
  37.    txtTips.width = txtTips.textWidth + 10;
  38.    drawBg();
  39.   }
  40.   //绘制背景
  41.   private function drawBg():void
  42.   {
  43.    graphics.clear();
  44.    graphics.beginFill(0xF3E789, .8);
  45.    graphics.lineStyle(1, 0xFFFF00);
  46.    graphics.drawRoundRect( -5, -5, txtTips.textWidth + 15, txtTips.textHeight + 15, 10, 10);
  47.    graphics.endFill();
  48.   }
  49.  }
  50.  
  51. }

使用方法:

//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 } );