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

per and dotted line

Get Adobe Flash player
by lizhi 12 Feb 2015
/**
 * Copyright lizhi ( http://wonderfl.net/user/lizhi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oxmk
 */

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Vector3D;
	/**
	 * ...
	 * @author lizhi
	 */
	public class Test extends Sprite
	{
		private var p2:P;
		private var p3:P;
		
		public function Test() 
		{
			p2 = new P("p2",100,100);
			addChild(p2);
			p3 = new P("p3",100,200);
			addChild(p3);
			addEventListener(Event.ENTER_FRAME, enterFrame);
		}
		
		private function enterFrame(e:Event):void 
		{
			var v2:Vector3D = new Vector3D(p2.x, p2.y, 0);
			var v3:Vector3D = new Vector3D(p3.x, p3.y, 0);
			var v12:Vector3D = v2.clone();
			v12.normalize();
			var v13:Vector3D = v3.clone();
			graphics.clear();
			graphics.lineStyle(0);
			graphics.lineTo(v2.x, v2.y);
			graphics.moveTo(0, 0);
			graphics.lineTo(v3.x, v3.y);
			
			var distance:Number = v13.dotProduct(v12);
			var d:Vector3D = v12.clone();
			d.scaleBy(distance);
			
			graphics.lineStyle(0, 0xff0000);
			graphics.moveTo(v2.x, v2.y);
			graphics.lineTo(d.x, d.y);
			graphics.lineTo(v3.x, v3.y);
			
			//r = l - n*2 * n.l;
			var n:Vector3D = d.subtract(v3);
			n.normalize();
			var l:Vector3D = v13.clone();
			var r:Vector3D = n.clone();
			r.scaleBy(2 * n.dotProduct(l));
			r = l.subtract(r);
			var v4:Vector3D = v3.add(r);
			graphics.lineTo(v4.x, v4.y);
		}
		
	}

}
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;

class P extends Sprite {
	public function P(name:String,x:Number,y:Number) 
	{
		super();
		this.x = x;
		this.y = y;
		this.name = name;
		var tf:TextField = new TextField;
		tf.mouseEnabled = tf.mouseWheelEnabled = false;
		tf.autoSize = "left";
		addChild(tf);
		tf.text = name;
		tf.x = -tf.width / 2;
		tf.y = -tf.height / 2;
		tf.textColor = 0xff0000;
		graphics.beginFill(0);
		graphics.drawCircle(0, 0, 10);
		addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
	}
	
	private function mouseDown(e:MouseEvent):void 
	{
		addEventListener(MouseEvent.MOUSE_UP, mouseUp);
		startDrag();
	}
	
	private function mouseUp(e:MouseEvent):void 
	{
		stopDrag();
	}
}