最近开始做FLEX开发,自己做了个淡入淡出效果类,留点痕迹。
调用方式:
// 淡入
var da:DisplayAlpha = new DisplayAlpha(pics,20,0.03);
da.show();
package common { import flash.display.DisplayObject; import flash.utils.setTimeout; // 淡入淡出 public class DisplayAlpha { // 需要淡入淡出的对象 private var _obj:DisplayObject; // 设置时间间隔 private var _delay:Number; // 记录淡入淡出的方向 private var _fx:int = 1; // 淡入淡出对象的最终alpha值 private var _value:Number; // appha递增(递减)的幅度 private var _alphaSpan:Number; public function DisplayAlpha(obj:DisplayObject,delay:Number,alphaSpan:Number=0.01) { _obj = obj; _delay = delay; if(_obj.alpha > 0) { _fx = -1; } _alphaSpan = alphaSpan; } // 淡出 public function hide():void { _obj.alpha -= _alphaSpan; if(_obj.alpha > 0) { setTimeout(hide,_delay); } else { _value = 0; setTimeout(setAlpha,500); } } // 淡入 public function show():void { _obj.alpha += _alphaSpan; if(_obj.alpha < 1) { setTimeout(show,_delay); } else { _value = 1; setTimeout(setAlpha,500); } } // 淡入淡出交替 public function autoShowAndHide():void { _obj.alpha += _fx*_alphaSpan; if(_obj.alpha >= 1 || _obj.alpha <= 0) { _fx = -_fx; } setTimeout(autoShowAndHide,_delay); } // 给淡入淡出对象赋值 private function setAlpha():void { _obj.alpha = _value; } } }