2010년 3월 17일 수요일

(2) 두 점 사이의 거리 - Point - distance()

[code as3]
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;

public class DistanceExample extends Sprite
{
 public function DistanceExample()
 {
  super();
  configureListener();
 }

 private var circle1:Circle;
 private var circle2:Circle;

 public function configureListener():void
 {
  if(!circle1)
  {
   circle1 = new Circle();
   circle1.x = 100;
   circle1.y = 100;
   addChild(circle1);
  }

  if(!circle2)
  {
   circle2 = new Circle();
   circle2.x = 200;
   circle2.y = 200;
   addChild(circle2);
  }

  circle1.addEventListener(MouseEvent.MOUSE_DOWN, circle1DownHandler);
circle1.addEventListener(MouseEvent.MOUSE_UP, circle1UpHandler);
circle2.addEventListener(MouseEvent.MOUSE_DOWN, circle2DownHandler);
circle2.addEventListener(MouseEvent.MOUSE_UP, circle2UpHandler);
}

 public function circle1DownHandler(event:MouseEvent):void
 {
  circle1.startDrag(false, null);
 }

 public function circle1UpHandler(event:MouseEvent):void
 {
  circle1.stopDrag();
  var point1:Point = new Point(circle1.x, circle1.y);
  var point2:Point = new Point(circle2.x, circle2.y);
  distance_txt.text = Point.distance(point1, point2).toString();
 }

 public function circle2DownHandler(event:MouseEvent):void
 {
  circle2.startDrag(false, null);
 }

 public function circle2UpHandler(event:MouseEvent):void
 {
  circle2.stopDrag();
  var point1:Point = new Point(circle1.x, circle1.y);
  var point2:Point = new Point(circle2.x, circle2.y);
  distance_txt.text = Point.distance(point1, point2).toString();
 }
}
}
[/code]

 

 

댓글 없음:

댓글 쓰기