Stoping an image at the edge of the stage
Hello all.
I'm creating a navigation bar for a website, and the client wants a little car to roll back and forth as you mouse over the buttons. Ok, that's easy enough, I say to myself, but I've run into a hitch.
When the page loads, (before you mouse over anything) the little car is sitting half off the stage, that is, only half the car is visible. I fixed that by putting the car symbol's registration point along the left side, but then the car's left edge is whats following the mouse. I need the cars center to be whats following the mouse, but at the same time, not be able to slide off the screen.
Not sure how to fix it.
Here is the code that is making the car follow the mouse:
Code:
stage.addEventListener(Event.ENTER_FRAME,followCar);
function followCar(event:Event):void {
var dx:int = car_mc.x - mouseX;
car_mc.x -= dx / 20;
}
...and, that's all the code I'm using so far.
(I have the horrible feeling one of my teachers from long ago explained exactly how to fix this, and I just can't remember)
Thank you all.