WDTM: What Does This Mean, i do not want to write long title :look:
i tried to understand the following code. it is drag and drop target.
below, i did not understand these lines:
offsetX = event.stageX - circle.x;
offsetY = event.stageY - circle.y;
what i figured out is the var offsetX store the stageX coordinate. but why there is " - circle.x". i deleted the " - circle.x", i noticed that the circle jump when i drag to position itself in center of my mouse.
//complete code
var offsetX:Number;
var offsetY:Number;
circle.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
circle.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function startDragging(event:MouseEvent):void {
offsetX = event.stageX - circle.x;
offsetY = event.stageY - circle.y;
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCircle);
}
function stopDragging(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragCircle);
}
function dragCircle(event:MouseEvent):void {
circle.x = event.stageX - offsetX;
circle.y = event.stageY - offsetY;
event.updateAfterEvent();
}