PDA

View Full Version : Problem with Tween



bigggidy
February 4th, 2009, 07:26 AM
Hello,

I am making an animation that tweens two different objects at different speeds dependent on the position of the mouse. This is working fine, however, when the user takes the cursor outside the flash box and enters the frame it jumps to that position.

I have created a tween for this first instance however, if the user continues to move there cursor before this tween has finished it continues to jump.

Your suggestions would be gratefully appreciated.
Here is the code I have written


stage.addEventListener(MouseEvent.MOUSE_MOVE, CheckDirection);


import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.utils.*;

var motionlayerX:Tween;
var motionlayer2X:Tween;
var curX:int = 0;
var curY:int = 0;
var preX:int = 0;
var n:int = 0;
var motion1:Number = 0;
var motion2:Number = 0;
var curmotion1:Number = 0;
var curmotion2:Number = 0;




function CheckDirection(e:MouseEvent)
{

curX = stage.mouseX;
curY = stage.mouseY;
curmotion1 = (curX * .25 +172);
curmotion2 = (curX * .10 +220);

// check boundary
if ( curX > 285 && curX < 905 && curY > 85 && curY < 283) {

// do motion tween
if ((preX != curX)){
if((curX > preX + 50) || (curX < preX - 50)){
motionX();
}else {
motionX();
}
}
// reset var
preX = curX;
motion1 = (preX * .25 +172);
motion2 = (preX * .10 +220);
}
}

function motionX()
{
motionlayerX = new Tween(motionlayer, "x", Regular.easeOut, motion1, curmotion1, 0.1, true);
motionlayer2X = new Tween(motionlayer2, "x", Regular.easeOut, motion2, curmotion2, 0.1, true);
}

cbeech
February 4th, 2009, 10:09 AM
i think that for a system that is based on mouse movement i would not use a tween, but rather a continuous calculation with a enterframe loop or timer - not triggered with MOUSE_MOVE (guessing ;) )