Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var original_x_:int = this.x;
- var original_y_:int = this.y;
- var answer_x_:int;
- var answer_y_:int;
- parent.addEventListener(MouseEvent.MOUSE_DOWN, DragMe);
- parent.addEventListener(MouseEvent.MOUSE_UP, DropMe);
- function DragMe(e:MouseEvent):void
- {
- this.startDrag();
- }
- function DropMe(e:MouseEvent):void
- {
- this.stopDrag();
- var dist_to_answer_x = this.x - answer_x_;
- var dist_to_answer_y = this.y - answer_y_;
- var acceptable_distance = 25;
- if (dist_to_answer_x * dist_to_answer_x + dist_to_answer_y * dist_to_answer_y < acceptable_distance)
- {
- this.x = answer_x_;
- this.y = answer_y_;
- } else
- {
- this.x = original_x_;
- this.y = original_y_;
- }
- }
- function AnswerPosition(x:int, y:int)
- {
- answer_x_ = answer_x;
- answer_y_ = answer_y;
- }
Add Comment
Please, Sign In to add comment