I have a draggable movieclip on my stage that is dragged simply by listening for MOUSE_MOVE, and updating its position by comparing the current mouse coordinates to old coordinates stored in a Point variable. Pretty standard stuff.
The problem I'm having appears when the user releases the mouse. I have TweenMax (and ThrowPropsPlugin) giving the movieclip some inertia-type movement based on delta of the mouse position.
Without updateAfterEvent(), the tween looks and performs normally no matter how fast you drag the mouse. But with updateAfterEvent(), if you release the mouse button while the mouse is moving, the movieclip instantly "teleports" about 100-200 pixels away from where it should be and the tween appears to complete in about half the time it should. This isn't an issue with ThrowPropsPlugin because ive seen this same behavior in another project that only uses TweenMax.
Any ideas? If the answer is "dont use updateAfterEvent" thats fine; I'd just like to have the smoothest mouse movement if possible.
My code is below if it helps. Thanks!
var dragDelta:Point; //Not an actual point, but the difference between the old mouse x/y position and the new
var dragPosOld:Point; //Storage point for old mouse values while dragging
public function officeHandler(evt:MouseEvent = null):void {
switch(evt.type){
case MouseEvent.MOUSE_DOWN:
TweenMax.killTweensOf( office.bg );
TweenMax.killTweensOf( office.btn );
dragPosOld.x = this.mouseX;
dragPosOld.y = this.mouseY;
addEventListener(MouseEvent.MOUSE_MOVE, officeDragHandler);
break;
case MouseEvent.MOUSE_UP:
removeEventListener(MouseEvent.MOUSE_MOVE, officeDragHandler);
var velX:Number = dragDelta.x * 50;
var velY:Number = dragDelta.y * 50;
var boundX:Number = (office.bg.scaleX-1)*1024;
var boundY:Number = (office.bg.scaleY-1)*768;
TweenMax.allTo([office.bg, office.btn], 1, {throwProps:{x:{velocity:velX, min:boundX*-1, max:0}, y:{velocity:velY, min: boundY*-1, max: 0}, resistance:200}, ease:Strong.easeOut});
break;
}
}
public function officeDragHandler(evt:MouseEvent):void {
evt.updateAfterEvent();
dragDelta.x = this.mouseX - dragPosOld.x;
dragDelta.y = this.mouseY - dragPosOld.y;
dragPosOld.x = this.mouseX;
dragPosOld.y = this.mouseY;
office.btn.x += dragDelta.x;
office.bg.x += dragDelta.x;
office.btn.y += dragDelta.y;
office.bg.y += dragDelta.y;
}
}