Hello,
I have a simple flight simulator animation. When the mouse is moved over a movieclip (mcHitArea) on the stage the code below moves 2 indicator lines as well as 2 jet images and the background. The problem is that when the mouse runs off, say, the left side of mcHitArea, that mouse location is recorded. Then if the mouse is brought back in from the other side of mcHitArea the images are rotated way off course. These images never come back to center.
Does anyone have any suggestions?
Thanks in advance.
var lastPointX:Number;
var lastPointY:Number;
var diffY:Number;
var diffX:Number;
var percentY:Number;
var percentX:Number;
// These variables make it possible to move the 2 indicator lines at author time, automatically setting the limits.
var leftLimit:Number = mcVertLine.x - 57;
var rightLimit:Number = mcVertLine.x + 57;
var topLimit:Number = mcHorizLine.y - 57;
var botLimit:Number = mcHorizLine.y + 57;
Mouse.hide();
mcStick.startDrag(true);
mcBeginMessage.btnContinue.addEventListener(MouseEvent.CLICK, handleBegin);
function handleBegin(evt:MouseEvent):void
{
lastPointX = mouseX;
lastPointY = mouseY;
mcBeginMessage.x = -300;
mcHitArea.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseLocation);
}
function handleMouseLocation(evt:Event):void
{
var thisPointY:Number = mouseY;
var thisPointX:Number = mouseX;
diffY = thisPointY - lastPointY;
diffX = (thisPointX - lastPointX)/1.4;
percentX = (diffX / thisPointX) * 6;
percentY = (diffY / thisPointY) * 6;
mcBackGrnd.rotation += percentX;
mcBackGrnd.y += percentY;
mcFront.rotation += (percentX)*2;
mcSide.rotation += (percentY)*2;
//trace(percentY);
if((mcHorizLine.y - diffY) > topLimit && (mcHorizLine.y - diffY)< botLimit)
{
mcHorizLine.y = mcHorizLine.y - diffY;
//trace("y = "+mouseY);
}
if((mcVertLine.x - diffX) > leftLimit && (mcVertLine.x - diffX)< rightLimit)
{
mcVertLine.x = mcVertLine.x - diffX;
//trace("x = "+mouseX);
}
lastPointY = thisPointY;
lastPointX = thisPointX;
}