矢印破線
/**
* Copyright 178ep3 ( http://wonderfl.net/user/178ep3 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ciSJ
*/
package
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
public class ArrowBreakLine extends Sprite
{
public function ArrowBreakLine()
{
var shape:Shape = addChild(new Shape())as Shape;
var flg:Boolean=true;
var p:Point = new Point(232,232);
stage.addEventListener(MouseEvent.CLICK,click);
stage.addEventListener(MouseEvent.MOUSE_MOVE,loop);
function loop(e:MouseEvent):void
{
shape.graphics.clear();
drawBreakLine(shape.graphics,p,new Point(mouseX,mouseY));
}
function click(e:MouseEvent):void
{
if(!flg)
{
p.x = mouseX;
p.y = mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE,loop);
}
else
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,loop);
}
flg = !flg;
}
}
private function drawBreakLine(g:Graphics,fromPoint:Point,toPoint:Point,width:Number=1,space:Number=3,color:int=0,alpha:Number=1):void
{
if(width<0)width = 0;
if(color<0)color = 0;
if(space<0)space = 0;
if(alpha<0)alpha = 0;
var dist:Number = Math.abs(Point.distance(fromPoint,toPoint));
var len:uint = dist/space/2;
var prev:Point = fromPoint;
var pa:Number=0;
var p:Point;
g.lineStyle(width,color,alpha);
for(var i:uint=0; i<len; i++)
{
pa = 1-i/len;
p = Point.interpolate(fromPoint,toPoint,pa);
if(i%2==0)
{
g.moveTo(prev.x,prev.y);
g.lineTo(p.x,p.y);
}
prev = p;
}
g.endFill();
drawArrow(g,fromPoint,toPoint,10,color,alpha);
p = null;
prev = null;
}
private var pi:Number = Math.PI/180;
private function drawArrow(g:Graphics,fromPoint:Point,toPoint:Point,size:Number=10,color:int=0,alpha:Number=1):void
{
if(color<0)color = 0;
if(alpha<0)alpha = 0;
var angle:Number = Math.atan2(toPoint.y-fromPoint.y,toPoint.x-fromPoint.x);
g.beginFill(color,alpha);
g.moveTo(toPoint.x + size*(Math.cos(angle)),toPoint.y + size*(Math.sin(angle)));
g.lineTo(toPoint.x + size*(Math.cos(angle+pi*120)),toPoint.y + size*(Math.sin(angle+pi*120)));
g.lineTo(toPoint.x + size*(Math.cos(angle+pi*240)),toPoint.y + size*(Math.sin(angle+pi*240)));
g.lineTo(toPoint.x + size*(Math.cos(angle)),toPoint.y + size*(Math.sin(angle)));
g.endFill();
}
}
}