package { import flash.display.Shape; import flash.display.Sprite; import flash.geom.Point; import flash.utils.Timer; import flash.events.TimerEvent; /** * ... * @author Default */ public class Arrow extends Sprite { private var _force:uint = 0; private var _fader:Shape; private var _timer:Timer; private var _delay:uint = 20; public function Arrow() { init(); } private function init():void { var length:uint = 200; // draw the main arrow graphics.lineStyle(0, 0xff0000); graphics.beginGradientFill("linear", [0xffff00, 0xff0000], [1.0, 1.0], [128, 255]); graphics.moveTo(0, -5); graphics.lineTo(length - 30, -5); graphics.lineTo(length - 30, -15); graphics.lineTo(length, 0); graphics.lineTo(length - 30, 15); graphics.lineTo(length - 30, 5); graphics.lineTo(0, 5); graphics.lineTo(0, -5); graphics.endFill(); // draw the fader mask _fader = addChild(new Shape) as Shape; _fader.x = length - 31; _fader.y = 0; _fader.graphics.beginFill(0xffffff, .75); _fader.graphics.drawRect( -(length - 32), -4, length - 32, 8); /*_fader.graphics.moveTo( -(length - 2), -4); _fader.graphics.lineTo( -28, -4); _fader.graphics.lineTo( -28, -14); _fader.graphics.lineTo(0, 0); _fader.graphics.lineTo( -28, 14); _fader.graphics.lineTo( -28, 4); _fader.graphics.lineTo( -(length - 2), 4); _fader.graphics.lineTo( -(length - 2), -4);*/ _fader.graphics.endFill(); // add a shape object to track the location of the tip var tipShape:Shape = addChild(new Shape) as Shape; tipShape.x = length; tipShape.y = 0; // the tip /*tipShape.graphics.beginFill(0xff0000); tipShape.graphics.drawCircle(0, 0, 1); tipShape.graphics.endFill();*/ // create timers for the force fade _timer = new Timer(_delay); _timer.addEventListener(TimerEvent.TIMER, updateForce); // set default rotation rotation = -45; } public function get tip():Point { var tipShape:Shape = getChildAt(0) as Shape; return localToGlobal(new Point(tipShape.x, tipShape.y)); } public function startForceUpdate():void { _timer.start(); } public function stopForceUpdate():void { _force = 0; _fader.scaleX = (100 - _force) / 100; _timer.reset(); _timer.delay = _delay; } private function updateForce(event:TimerEvent):void { // add slight delay when force is max if (_force == 100) { _timer.delay = _delay * 10; _force++; return; } if (_force > 100) { _timer.delay = _delay; _force = 0; } _force++; _fader.scaleX = (100 - _force) / 100; } public function get force():uint { return _force; } } }