文字闪烁提示

简介: 当数字发生改变时,数字变大则呈现绿色的闪烁,变小则呈现红色闪烁。   只是把以前JavaScript对DOM的操作,改用as3写了一个共用类,不限于更改文字颜色。 package com.

当数字发生改变时,数字变大则呈现绿色的闪烁,变小则呈现红色闪烁。

 

只是把以前JavaScript对DOM的操作,改用as3写了一个共用类,不限于更改文字颜色。

package com.tool
{
import flash.utils.clearTimeout;
import flash.utils.setTimeout;

public class NotifyManager
{
public function NotifyManager()
{
}

public var onUpdateFn:Function;
public var onUpdateFnArgs:Array;
public var onCompleteFn:Function;
public var onCompleteFnArgs:Array;

private var arr:Array;
private var delayTimer:uint;

/**
* 销毁方法
*/
public function dispose():void
{
clearDelayTimer();
}

/**
* 播放
*/
public function play():void
{
arr = timeArr.concat();

onUpdate();
}

public function clear():void
{
dispose();

arr = null;
onUpdateFn = null;
onUpdateFnArgs = null;
onCompleteFn = null;
onCompleteFnArgs = null;
}

private function onUpdate():void
{
clearDelayTimer();

var t:Object = arr.shift();
if (t && t.t)
{
var args:Array;

if (t.v)
{
args = onUpdateFnArgs.concat(true);
}
else
{
args = onUpdateFnArgs.concat(false);
}

onUpdateFn && onUpdateFn.apply(null, args);

delayTimer = setTimeout(onUpdate, t.t * 1000);
}
else
{
onComplete();
}
}

private function onComplete():void
{
onCompleteFn && onCompleteFn.apply(null, onCompleteFnArgs);

dispose();
}

private function clearDelayTimer():void
{
if (delayTimer)
{
clearTimeout(delayTimer);
delayTimer = 0;
}
}



private static var timeArr:Array = [
{t: 0.07, v: 1},
{t: 0.07, v: 0},
{t: 0.07, v: 1},
{t: 0.07, v: 0},
{t: 0.07, v: 1},
{t: 0.07, v: 0},
{t: 0.07, v: 1},
{t: 0.07, v: 0}
];

private static var _notifyArr:Array = [];

/**
* 播放通知动画
*/
public static function notify(updateFn:Function=null, updateFnArgs:Array=null, completeFn:Function=null, completeFnArgs:Array=null):NotifyManager
{
var notify:NotifyManager = new NotifyManager();
notify.onUpdateFn = updateFn;
notify.onUpdateFnArgs = updateFnArgs || [];
notify.onCompleteFn = completeFn;
notify.onCompleteFnArgs = completeFnArgs || [];

_notifyArr.push(notify);

notify.play();

return notify;
}

/**
* 清除通知
*/
public static function clear(notify:NotifyManager):void
{
if (notify)
{
for (var i:int = 0, len:int = _notifyArr.length; i < len; i++)
{
var _notify:NotifyManager = _notifyArr[i] as NotifyManager;

if (_notify == notify)
{
_notifyArr.splice(i, 1);
break ;
}
}

notify.clear();
}
}

}
}

使用方法也很简单,只需要调用NotifyManager类的notify方法,传入需要回调的函数(每次调用时的回调、完成时的回调,支持回传参数)

 

以截图中的demo为例:

   1: import com.tool.NotifyManager;
   2: import flash.events.MouseEvent;
   3: import flash.events.Event;
   4:  
   5: btn1.buttonMode = true;
   6: btn2.buttonMode = true;
   7:  
   8: var txtNotify:NotifyManager;
   9:  
  10: btn1.addEventListener(MouseEvent.CLICK, onClickHandler1);
  11: btn2.addEventListener(MouseEvent.CLICK, onClickHandler2);
  12:  
  13: function onClickHandler1(evt:MouseEvent):void
  14: {
  15:     notifyHandler(0xFF0000);
  16: }
  17:  
  18: function onClickHandler2(evt:MouseEvent):void
  19: {    
  20:     notifyHandler(0x00FF00);
  21: }
  22:  
  23: function notifyHandler(color:uint):void
  24: {
  25:     NotifyManager.clear(txtNotify);
  26:     
  27:     txtNotify = null;
  28:     txtNotify = NotifyManager.notify(changeTxtColorHandler, [color], null, null);
  29: }
  30:  
  31: function changeTxtColorHandler(color:uint, bool:Boolean):void
  32: {
  33:     var tf:TextFormat = new TextFormat();
  34:     tf.color = bool ? color : 0x000000;
  35:     
  36:     //txt.setStyle("textFormat", tf);
  37:     txt.setTextFormat(tf);
  38: }

示例使用CS5.5编写,需要使用Flash CS5.5打开。 点此下载所有源码>>
目录
相关文章
|
4月前
|
前端开发 C++
css 鼠标悬浮显示放大图片 vs 鼠标点击显示放大图片
css 鼠标悬浮显示放大图片 vs 鼠标点击显示放大图片
46 0
|
6月前
div 文字溢出文字自动隐藏显示
div 文字溢出文字自动隐藏显示
57 0
鼠标悬浮显示文字的简单方法
鼠标悬浮显示文字的简单方法
167 0
点击文字显示,点击文字隐藏(3)
点击文字显示,点击文字隐藏(2)
|
JavaScript
点击文字显示,点击文字隐藏(5)
点击文字显示,点击文字隐藏(5)
PS解决取色器不能粘贴颜色码(重置取色器)
PS解决取色器不能粘贴颜色码(重置取色器)
218 1