import mx.transitions.Tween; import mx.transitions.easing.Regular; import mx.utils.Delegate; class Throbber extends MovieClip { private var _leafSize:Number = 8; private var _color:Number = 0x808080; private var _leafCount:Number = 8; private var _circleRadius:Number = 14; private var _padding:Number = 10; private var throbber:MovieClip; private var intervalArray:Array; private var tweenArray:Array; // no constructor function init(width:Number, height:Number) { this.throbber = this.createEmptyMovieClip("throbber", this.getNextHighestDepth()); this.throbber._x = this._circleRadius + this._padding; this.throbber._y = 0; this.intervalArray = new Array(); this.tweenArray = new Array(); var offsetMilliseconds = new Date().getMilliseconds(); for (var i=1; i <= this._leafCount; i++) { this.throbber["leaf" + i] = this.throbber.createEmptyMovieClip("leaf" + i, this.throbber.getNextHighestDepth()); this.drawLeafCircle(this.throbber["leaf" + i], (Math.cos((i * (360 / this._leafCount)) * (3.14/180)) * this._circleRadius), (Math.sin((i * (360 / this._leafCount)) * (3.14/180)) * this._circleRadius)); //this.drawLeafStub(this.throbber["leaf" + i], (Math.cos((i * (360 / this._leafCount)) * (3.14/180)) * this._circleRadius), (Math.sin((i * (360 / this._leafCount)) * (3.14/180)) * this._circleRadius)); this.throbber["leaf" + i]._alpha = 25; this.intervalArray[i] = setInterval( Delegate.create(this, function (i) { this.tweenArray[i] = new Tween(this.throbber["leaf" + i], "_alpha", Regular.easeOut, 100, 25, 1, true); this.tweenArray[i].onMotionFinished = function () { this.rewind(); this.start(); }; clearInterval(this.intervalArray[i]); } ) , (((1000 / this._leafCount) * i) - (new Date().getMilliseconds() - offsetMilliseconds)), i); } } function drawLeafStub (target:MovieClip, x:Number, y:Number) { target.lineStyle(this._leafSize, this._color, 100); target.moveTo(x, y); target.lineTo(x*1.5, y*1.5); } function drawLeafCircle (target:MovieClip, x:Number, y:Number) { var w = this._leafSize; var h = this._leafSize; // center the circle w /= 2; h /= 2; x += w; y += h; var xc1 = w*(Math.SQRT2-1), xc2 = w*(Math.SQRT2/2); var yc1 = h*(Math.SQRT2-1), yc2 = h*(Math.SQRT2/2); target.lineStyle(0, this._color, 100); target.beginFill(this._color); target.moveTo(x+w, y); target.curveTo(x+w, y+yc1, x+xc2, y+yc2); target.curveTo(x+xc1, y+h, x, y+h); target.curveTo(x-xc1, y+h, x-xc2, y+yc2); target.curveTo(x-w, y+yc1, x-w, y); target.curveTo(x-w, y-yc1, x-xc2, y-yc2); target.curveTo(x-xc1, y-h, x, y-h); target.curveTo(x+xc1, y-h, x+xc2, y-yc2); target.curveTo(x+w, y-yc1, x+w, y); target.endFill(); } /* It is important to stop previous Tween object instantiation if this class * is to be created/removed more than once in a specific animation */ function _close () { for (var tCnt in this.tweenArray) { this.tweenArray[tCnt].stop(); delete(this.tweenArray[tCnt]); } for (var iCnt in this.intervalArray) { clearInterval(this.intervalArray[iCnt]); delete(this.intervalArray[iCnt]); } this.removeMovieClip(); } }