zoukankan      html  css  js  c++  java
  • AS3淡入淡出类

    最近开始做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;
            }
        }
    }
  • 相关阅读:
    Xamarin.Forms之界面设计原则
    Xamarin.Forms之异步
    Xamarin Studio常见问题
    Xamarin.Forms之Button
    Xamarin.Forms之MessagingCenter
    Xamarin.Forms之Frame布局
    Xamarin.Forms之OnPlatform的使用
    2018/11/7 20:47:57
    2018/11/6
    2018/11/5 每日分析-test
  • 原文地址:https://www.cnblogs.com/mimengjiangnan/p/2859998.html
Copyright © 2011-2022 走看看