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: }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Android知识点总结

看得见的数据结构Android版之栈篇

进入和弹出动画为了好区分,用两个 ValueAnimator 控制,下面是成员变量

1112
来自专栏互联网杂技

JavaScript 常用方法总结

经常使用的 JS 方法,今天记下,以便以后查询 /* 手机类型判断 */ var BrowserInfo = { userAgent: navigator.us...

3736
来自专栏我就是马云飞

直播间气泡效果

这个效果是之前看过的,正好是很典型的跟动画相关的例子,我这里就拿来跟大家分享一下,如果你以前看过又很熟悉动画那就可以略过,如果不是很熟悉或者没看过那...

2515
来自专栏java沉淀

java生成二维码例子及Qrcode.jar包(demo小例子)

2193
来自专栏androidBlog

常用的自定义控件四(QuickBarView)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gdutxiaoxu/article/details/...

941
来自专栏琯琯博客

JavaScript 103 条技能

1、原生JavaScript实现字符串长度截取 function cutstr(str, len) { var temp; var ic...

2876
来自专栏Code_iOS

OpenGL ES 2.0 Making the Hardware Work for You

iOS 系统会通过一个称之为 Core Animation Compositor (核心动画合成器[系统组件])去控制最终在屏幕显示的图像。

1052
来自专栏蜉蝣禅修之道

android之自定义渐变颜色(二)

1602
来自专栏游戏杂谈

利用threshold实现的遮罩引导

点击“开始引导”,则进入引导操作。除指定的按钮可以操作外,其它区域均不可点击。这种应用当新功能或是新产品上线后,用来引导用户来使用产品/功能,是十分有用的。fa...

1061
来自专栏码农阿宇

利用GDI+在Winfrom绘制验证码

string yzm; private void yangzhengma() { Bitma...

2997

扫码关注云+社区

领取腾讯云代金券