Hello,
I am making an animation that shows roughly how an airplane’s localizer works. (It is a guage in the cockpit that tells you the angle of the plane) This explanation might be a bit hard to follow, bear with me. Anyway, when the user moves the mouse side to side, the verticle line on the guage moves side to side. And when the users moves the mouse up and down the horizontal line moves up and down. I have set up limits to how far these lines can move in the guage. The problem I am having is that when you move the mouse in one direction, the coresponding line hits its limit and stops, but if you keep moving the mouse in that direction, stop, and then move the mouse in the opposite direction, the line begins tracking immediately from that point, so now your mouse location is off center from where it should be.
So, is there a way to also limit the active area on the screen so that mouse movement only registers in that area?
Thanks in advance.
var lastPointX:Number;
var lastPointY:Number;
var diffY:Number;
var diffX: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;
mcBeginMessage.btnContinue.addEventListener(MouseEvent.CLICK, handleBegin);
function handleBegin(evt:MouseEvent):void
{
lastPointX = mouseX;
lastPointY = mouseY;
mcBeginMessage.x = -300;
stage.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;
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;
}