0 Replies - 1113 Views - Last Post: 19 October 2009 - 06:09 AM

#1 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1490
  • View blog
  • Posts: 8,217
  • Joined: 07-September 06

Draw Arrow [AS3]

Posted 19 October 2009 - 06:09 AM

Description: Copy and paste into AS3 and call to useDraws a verticle arrow from one point to another.
function createArrow(from:Point, to:Point):MovieClip{
	var a:MovieClip = new MovieClip();
	var b:MovieClip = new MovieClip();
	var g:Graphics = a.graphics;
	var flag:Boolean;
	if(from.y < to.y){
		to.y -= 10;
		flag = true;
	}
	else{
		to.y += 10;
		flag = false;
	}
	a.x = a.y = 0;
	g.lineStyle(1, 0x000000, 1);
	g.moveTo(from.x, from.y);
	g.lineTo(from.x, (to.y+from.y)/2);
	g.lineTo(to.x, (to.y+from.y)/2);
	g.lineTo(to.x, to.y);
	drawTriangle(to, b.graphics, flag);
	a.addChild(b);
	return a;
}
function drawTriangle(pt:Point, g:Graphics, flag:Boolean=false):void{
	g.moveTo(pt.x, pt.y);
	g.beginFill(0x000000);
	g.lineTo(pt.x-5, pt.y);
	g.lineTo(pt.x, pt.y+(!flag?-10:10));
	g.lineTo(pt.x+5, pt.y);
	g.lineTo(pt.x, pt.y);
	g.endFill();
}
var mc:MovieClip = createArrow(new Point(20, 200), new Point(50, 100));
addChild(mc);


Is This A Good Question/Topic? 0
  • +

Page 1 of 1