flex 加载数据时的动画效果

//

package hxht.comps.round
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.text.TextField;

    import mx.core.UIComponent;

    /**
     *
     * @author Administrator
     */
    public class RoundLavel extends UIComponent
    {
        /**
         * 加载效果动画类
         * @param width
         * @param height
         * @param roudr
         * @param showPross
         * @param loadtext
         * @param textposition
         */
        public function RoundLavel(width:Number = 100, height:Number = 100, roudr:Number = 40, showPross:Boolean = false, loadtext:String = "", textposition:String = "bottom")
        {
            super();
            roudR = 40;
            this.width = width;
            this.height = height;
            this.loadText = loadtext;
            this.textPosition = textposition;
            showProssText = showPross;
            this.addEventListener(Event.ENTER_FRAME, farmeHandler);
        }

        private var dfff:Boolean = true;

        /**
         *
         * @default
         */
        public var color:uint = 0x0000ff;

        /**
         *
         * @default
         */
        public var colorAlpha:Number = .6;

        /**
         *
         * @default
         */
        public var roudR:Number = 40;

        private var loadText:String = "";

        /**
         *
         * @default
         */
        public var arrd:Array = [ 345, 26, 60, 100, 140, 180, 220, 260 ];

        private var dddd:Number = 2;

        private var u:UIComponent;

        private var _sprit:Sprite;

        /**
         *
         * @default
         */
        public var speed:Number = 24;

        private var _text:TextField;

        private var showProssFlag:Boolean = false;

        private var textPosition:String = "bottom";

        private var playTime:int = 0;

        private var rounds:Vector.<Sprite> = new Vector.<Sprite>();


        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            updateText();
        }

        /**
         *
         * @param v
         */
        public function set showProssText(v:Boolean):void
        {
            showProssFlag = v;
            if (showProssFlag)
            {
                _text = new TextField();
                _text.mouseEnabled = false;
                this.addChild(_text);
                updateText();
            }
        }

        /**
         *
         * @param v
         */
        public function set label(v:String):void
        {
            this.loadText = v;
            updateText();
        }

        /**
         *
         * @return
         */
        public function get label():String
        {
            return loadText;
        }

        /**
         *
         */
        protected function updateText():void
        {
            if (_text != null)
            {
                _text.text = loadText;
                _text.width = _text.textWidth;
                _text.x = (this.width - _text.textWidth) / 2;
                _text.y = roudR + (roudR - 20) + 10;
            }
        }

        override protected function createChildren():void
        {
            super.createChildren();
            drawRound();
        }

        /**
         *
         */
        protected function drawRound():void
        {
            this.graphics.clear();

            var p:Point;
            var _round:Sprite;
            var _r:Number;

            for (var i:int = 0; i < arrd.length; i++)
            {
                p = getPointOnScrile(roudR, roudR, (roudR - 20), arrd[i]);

                _round = new Sprite();
                _r = (dddd * (1 + i * 0.2));
                _round.graphics.beginFill(color, colorAlpha);
                _round.graphics.drawCircle(_r, _r, _r);
                _round.graphics.endFill();
                _round.x = p.x - _r;
                _round.y = p.y - _r;
                rounds.push(_round);

                this.addChild(_round);
            }
        }

        /**
         *
         */
        protected function updateRound():void
        {
            var p:Point;
            var _round:Sprite;
            var _r:Number;
            for (var i:int = 0; i < arrd.length; i++)
            {
                p = getPointOnScrile(roudR, roudR, (roudR - 20), arrd[i]);

                _round = rounds[i];
                _r = (dddd * (1 + i * 0.2));
                _round.x = p.x - _r;
                _round.y = p.y - _r;
            }
        }

        /**
         *
         */
        public function play():void
        {
            dfff = true;
            this.visible = true;
            playTime = 0;
        }

        /**
         *
         */
        public function stop():void
        {
            dfff = false;
            playTime = 0;
            this.visible = false;
        }

        /**
         *
         * @param v
         */
        public function set playFlag(v:Boolean):void
        {
            if (v)
                play();
            else
                stop();
        }

        /**
         *
         * @return
         */
        public function get isPlay():Boolean
        {
            return dfff;
        }

        /**
         *
         * @return
         */
        public function get playCountTime():int
        {
            return playTime * 24;
        }

        /**
         *
         * @param e
         */
        protected function farmeHandler(e:Event):void
        {
            if (dfff && this.initialized)
            {
                playTime++;
                var len:int = arrd.length;
                for (var i:int = 0; i < len; i++)
                {
                    arrd[i] += speed;
                    if (arrd[i] > 360)
                    {
                        arrd[i] = (arrd[i] - 360);
                    }
                }
                updateRound();
            }
        }


        /**
         *
         * @param x
         * @param y
         * @param r
         * @param angle
         * @return
         */
        protected function getPointOnScrile(x:Number, y:Number, r:Number, angle:Number):Point
        {
            var _angle:Number = angle * Math.PI / 180;
            var _re:Point = new Point();
            _re.x = x + r * Math.cos(_angle);
            _re.y = y - r * Math.sin(_angle);

            return _re;
        }

    }
}

 

//

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx"
       width="100%"
       height="100%"
       styleName="loadingmask"
       visible="{loadingFlag}"
       includeInLayout="{loadingFlag}"
       xmlns:round="hxht.comps.round.*">
 <fx:Script>
  <![CDATA[
   [Bindable]
   public var loadingFlag:Boolean=false;

   [Bindable]
   public var label:String="";
  ]]>
 </fx:Script>
 <round:RoundLavel playFlag="{loadingFlag}"
       width="100"
       height="100"
       verticalCenter="0"
       horizontalCenter="0"
       label="{label}"/>
</s:BorderContainer>

 

// true 加载, false 不加载

<win:Loading loadingFlag="{Boolean}"/>

你可能感兴趣的:(flex代码片段)