Guest User

Untitled

a guest
May 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var original_x_:int = this.x;
  2. var original_y_:int = this.y;
  3. var answer_x_:int;
  4. var answer_y_:int;
  5.  
  6. parent.addEventListener(MouseEvent.MOUSE_DOWN, DragMe);
  7. parent.addEventListener(MouseEvent.MOUSE_UP, DropMe);
  8.  
  9. function DragMe(e:MouseEvent):void
  10. {
  11.   this.startDrag();
  12. }
  13. function DropMe(e:MouseEvent):void
  14. {
  15.   this.stopDrag();
  16.   var dist_to_answer_x = this.x - answer_x_;
  17.   var dist_to_answer_y = this.y - answer_y_;
  18.   var acceptable_distance = 25;
  19.   if (dist_to_answer_x * dist_to_answer_x + dist_to_answer_y * dist_to_answer_y < acceptable_distance)
  20.   {
  21.     this.x = answer_x_;
  22.     this.y = answer_y_;
  23.   } else
  24.   {
  25.     this.x = original_x_;
  26.     this.y = original_y_;
  27.   }
  28. }
  29. function AnswerPosition(x:int, y:int)
  30. {
  31.   answer_x_ = answer_x;
  32.   answer_y_ = answer_y;
  33. }
Add Comment
Please, Sign In to add comment