package { import flash.display.*; import flash.events.*; public class MouseDistance extends Sprite { var s:String; var oneShape:Shape; var twoShape:Shape; public function MouseDistance() { init(); } private function init():void { oneShape=new Shape(); twoShape=new Shape(); addChild(oneShape); addChild(twoShape); t0.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunc); t1.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunc); t2.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunc); t3.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunc); d0.addEventListener(MouseEvent.MOUSE_UP, mouseUpFunc); d1.addEventListener(MouseEvent.MOUSE_UP, mouseUpFunc); d2.addEventListener(MouseEvent.MOUSE_UP, mouseUpFunc); d3.addEventListener(MouseEvent.MOUSE_UP, mouseUpFunc); } private function mouseDownFunc(e:Event):void { s = e.target.name.charAt(1); stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunc); } private function mouseUpFunc(e:Event):void { twoShape.graphics.lineStyle(1, 0, 1); twoShape.graphics.moveTo(this["t"+s].x,this["t"+s].y); twoShape.graphics.lineTo(e.currentTarget.x,e.currentTarget.y); oneShape.graphics.clear(); stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunc); this["t"+s].removeEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunc); e.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, mouseUpFunc); } private function mouseMoveFunc(e:Event):void { oneShape.graphics.clear(); oneShape.graphics.lineStyle(1, 0, 1); oneShape.graphics.moveTo(this["t"+s].x,this["t"+s].y); oneShape.graphics.lineTo(mouseX, mouseY); } }}