A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Stoping an image at the edge of the stage

  1. #1
    Junior Member
    Join Date
    Nov 2007
    New England

    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:

    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.
    The problem with being the office expert on something, is you have no one to talk to when you have a problem...

  2. #2
    Join Date
    Dec 2009
    You could us an if() statement to prevent the car from going too far in either direction. Something like this:
        var dx:int = car_mc.x - mouseX;
        car_mc.x-= dx/20;
    This will make the car only follow the mouse if the mouse if greater than half the width of the car away from the left edge. Hope this helps.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center