Jump to content
Search Community

updateAfterEvent() and MOUSE_MOVE short circuiting my tweens?

dmb85 test
Moderator Tag

Recommended Posts

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;

 }
}

Link to comment
Share on other sites

try moving evt.updateAfterEvent() to the bottom of the method. Not so sure it will help but I've seen cases where it makes a difference.

 

 

public function officeDragHandler(evt:MouseEvent):void {

  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;
  evt.updateAfterEvent();
 }

Link to comment
Share on other sites

Unfortunately it still has this issue no matter where the evt.updateAfterEvent is called. I also tried messing around with the event priorities, making the MOUSE_UP and MOUSE_DOWN events at priority 99, but that had no effect. I'm kind of stumped as it doesn't appear to matter when updateAfterEvent is being called, merely that it's being called.

Link to comment
Share on other sites

Are you moving the object that your MOUSE_MOVE event listener is attached to inside the handler itself maybe? It's tough to diagnose this without seeing the rest of your code and a sample FLA that we can publish for ourselves, but imagine this scenario: You attach a MOUSE_MOVE listener to myObject, thus it fires anytime the mouse changes position over the top of myObject. Then, let's say inside that handler, you do something that moves/scales/rotates myObject (or any of its ancestors) - that would in fact alter where mouseX and mouseY is located on myObject, causing another MOUSE_MOVE event. However, it wouldn't actually kick in until the screen is updated which is precisely what the MouseEvent.updateAfterEvent() does.

 

Again, just a total guess. If you still need help, please post a very simple example (not your production files - only the simplest, concise example you can create in a separate FLA).

 

[unsolicited advice:] be careful about rounding errors that tend to creep in when you track only the delta in positions and apply them fresh on each movement/frame. It is subtle at first, but it adds up over time and I wouldn't really recommend that technique. It is usually better to work with absolutes.

Link to comment
Share on other sites

Unfortunately I'm not applying movement anywhere aside from the MOUSE_MOVE handler. But thank you for pointing out the delta/rounding issues thing, I had not even considered that.

 

 

I've made up a simple example showing the issue. I've included the version of the v11 codebase I'm using in case that matters.

 

Hmm, the forums wouldn't let me upload any file... heres a remote location you can grab it from:

[link removed because it contained members-only plugins and classes]

 

Thanks so much for your help and time!

Link to comment
Share on other sites

First of all, thanks for creating such a thorough (and simple) example file! I wish everyone in the forums was like you.

 

Anyway, I opened and published your FLA on both a Windows and Mac, CS5.5 and CS6 and I couldn't replicate the issue you talked about. I even opened your .swf (not republished by me) and couldn't see any difference between the behavior of box 1 and box 2, whether I was moving my mouse or not when I released the mouse button. [scratches head].

 

How can I reproduce the issue? Any other clues? Can anyone else see the odd behavior? Have you tried on a different system? I wonder if you have some weird corrupt Flash install. Or maybe I'm totally missing something obvious.

 

Oh, and I had to remove the link because it contained members-only plugins and classes.

Link to comment
Share on other sites

Oh, and I had to remove the link because it contained members-only plugins and classes.

 

Sorry about that; I've deleted that file from the site.

 

If you cannot see the issue then it may be something specific to my machine. I've only tested it there. I will test it on a few other machines and see if I can replicate it there, and report back my findings.

 

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...