as3--简单的文字提示队列



_______________________________________________________________

设定队列长度为3,超出的长度,直接调用其消失方法即可。唯一不同的是,注意添加参数overwrite,并设置其值为1。这里有关于overwrite值的详情介绍:

OverwriteManager – control how (and if and when) tweens get overwritten>>

[AS3] 请问tweenlite的overwrite问题>>

 

code:

   1: package  
   2: {
   3:     import flash.display.Bitmap;
   4:     import flash.display.BitmapData;
   5:     import flash.display.Sprite;
   6:     import flash.filters.GlowFilter;
   7:     import flash.text.TextField;
   8:     import flash.text.TextFormat;
   9:     import flash.text.TextFormatAlign;
  10:     import gs.TweenLite;
  11:     /**
  12:      * ...
  13:      * @author Meteoric
  14:      */
  15:     public class TextMessage extends Sprite
  16:     {
  17:         private var textFormat:TextFormat = new TextFormat("Arial", 14, 0x00FF00, true);
  18:         private var glowFilter:GlowFilter = new GlowFilter(0x000000, 0.7, 2, 2, 12, 5);
  19:         
  20:         private var txtArr:Array = [];
  21:         private var tweenArr:Array = [];
  22:         
  23:         private var defaultY:Number = 80;
  24:         
  25:         public function TextMessage() 
  26:         {
  27:             this.mouseEnabled = false;
  28:             this.mouseChildren = false;
  29:         }
  30:         
  31:         public function addText(txt:String, isHTML:Boolean = false):void
  32:         {
  33:             textFormat.letterSpacing = 2;
  34:             
  35:             var sprite:Sprite = new Sprite();
  36:             addChild(sprite);
  37:             
  38:             var textField:TextField = new TextField;
  39:             textField.autoSize = TextFormatAlign.LEFT;
  40:             textField.htmlText = txt;
  41:             
  42:             if (!isHTML) 
  43:             {
  44:                 textField.setTextFormat(textFormat);
  45:             }
  46:             
  47:             var bmp:Bitmap = new Bitmap();
  48:             var bmpData:BitmapData = new BitmapData(textField.width, textField.height, true, 0x00000000);
  49:             bmpData.draw(textField);
  50:             
  51:             bmp.bitmapData = bmpData;
  52:             bmp.x = -bmp.width / 2;
  53:             bmp.filters = [glowFilter];
  54:             bmp.smoothing = true;
  55:             
  56:             sprite.addChild(bmp);
  57:             
  58:             sprite.width = bmp.width * 1.3;
  59:             sprite.height = bmp.height * 1.3;
  60:             sprite.x = 200;
  61:             sprite.y = 120;
  62:             
  63:             txtArr.push(sprite);
  64:             
  65:             var aryLen:int = txtArr.length;
  66:             
  67:             for (var i:int = 0, len:int = aryLen - 3; i < len; i++)
  68:             {
  69:                 var tempSprite:Sprite = txtArr[i] as Sprite;
  70:                 
  71:                 TweenLite.to(tempSprite, 0.2, {width:sprite.width, height:sprite.height, alpha:0, onComplete:onCompleteFunc, onCompleteParams:[tempSprite], overwrite:1});
  72:             }
  73:             
  74:             TweenLite.to(sprite, 0.2, {width:bmp.width, height:bmp.height, overwrite:1});
  75:             TweenLite.to(sprite, 0.4, {width:sprite.width, height:sprite.height, alpha:0, delay:3, onComplete:onCompleteFunc, onCompleteParams:[sprite], overwrite:0});
  76:             
  77:             len = aryLen > 3 ? aryLen - 3 : 0;
  78:             for (i = aryLen - 1; i >= len; i--)
  79:             {
  80:                 var _y:int = -27 * (aryLen - i - 1) + 100;
  81:                 TweenLite.to(txtArr[i], 0.2+(aryLen-i-1)*0.2, {y:_y,overwrite:0});
  82:             }            
  83:         }
  84:         
  85:         private function onCompleteFunc(param_1:Sprite):void 
  86:         {
  87:             
  88:             var len:int = txtArr.length;
  89:             
  90:             for (var i:int = 0; i <  len; i++)
  91:             {
  92:                 if (txtArr[i] == param_1)
  93:                 {
  94:                     var bmp:Bitmap = param_1.getChildAt(0) as Bitmap;
  95:                     bmp.bitmapData.dispose();
  96:                     param_1.removeChild(bmp);
  97:                     bmp = null;
  98:                     txtArr.splice(i,1);                    
  99:                     this.removeChild(param_1);
 100:                     param_1 = null;
 101:                     break;
 102:                 }
 103:             }
 104:         }
 105:         
 106:     }
 107:  
 108: }
posted @ 2012-10-30 20:34  meteoric_cry  阅读(763)  评论(0编辑  收藏  举报