In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

arrow

Get Adobe Flash player
by imo_ 31 Jan 2013
/**
 * Copyright imo_ ( http://wonderfl.net/user/imo_ )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yfoY
 */

package  {
    import flash.display.*;
    import flash.events.*;
    [SWF(width = "400", height = "400", frameRate = "60")]
    public class ArrowTest extends Sprite {
        private var arrow:Arrow;
        private var cx:Number;
        private var cy:Number;
        
        public function ArrowTest() {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            cx = 200;
            cy = 200;
            arrow = new Arrow(0xff2020);
            addChild(arrow);
            arrow.setArrow(cx, cy, cx + 80, cy - 20);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
        }
        
        private function onMove(e:Event = null):void {
            arrow.setArrow(cx, cy, mouseX, mouseY);
        }
        
    }

}

import flash.display.*;

class Arrow extends Sprite {
    private var color:uint;
    public var x1:Number;
    public var y1:Number;
    public var x2:Number;
    public var y2:Number;
    
    public function Arrow(color:uint) {
        this.color = color;
    }
    
    public function setArrow(x1:Number, y1:Number, x2:Number, y2:Number):void {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        var g:Graphics = graphics;
        g.clear();
        g.lineStyle(4, color, 1);
        g.moveTo(x1, y1);
        g.lineTo(x2, y2);
        g.lineStyle();
        g.beginFill(color, 1);
        var ang:Number = Math.atan2(y2 - y1, x2 - x1);
        g.moveTo(x2 + Math.cos(ang) * 10, y2 + Math.sin(ang) * 10);
        ang += Math.PI * 2 / 3;
        g.lineTo(x2 + Math.cos(ang) * 10, y2 + Math.sin(ang) * 10);
        ang += Math.PI * 2 / 3;
        g.lineTo(x2 + Math.cos(ang) * 10, y2 + Math.sin(ang) * 10);
        g.endFill();
    }
}