A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: F8 - Need help slowing/stopping movement at two set extremes

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2

    F8 - Need help slowing/stopping movement at two set extremes

    Using Flash 8 - AS2

    I am proud of myself for getting this far, but I cannot figure the rest

    I have a movie clip that moves from side to side based on the position of the mouse. If the mouse is right of center, the movie clip moves left, the speed based on the distance of the pointer to the center. Conversely, the same for the other direction.

    Here's the AS on the clip event:

    PHP Code:
    onClipEvent(load){
        
    speed=10;
    }
    onClipEvent(enterFrame){
        
    this._x += (_root.center-_root._xmouse)/speed;


    (the speed variable is just a simple method to slow down my motion.)

    Now what I need it to do and can't figure out out is this:
    > How to get it to have upper and lower limits of motion.
    > How to get it to slow down and stop at the upper and lower limits
    > How to get it to stop at the limit until the mouse triggers movement back in the other direction

    Logically, it could be said in this manner:
    1) Move the clip right or left based on mouse position.
    2) If clip _x nears the maximum (or minimum), change speed as a function of the distance remaining to the extent - in order to slow down the movement.
    3) When clip _x reaches the maximum (or minimum), stop motion and permit no further motion in that direction.

    Any ideas on this? Apologies if I am not being clear - I am not a programmer but have always done thing using keyframe animation.

    Thanks

  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Update - see if you guys can make sense of this. This is closer, but still not what I'm looking for, because it changes the movement too much. My previous code stops the movement if the mouse is at center, and speeds it up in either direction as the mouse is moved away from center.

    This code successfully creates endpoints, but the clip leaps out of center to move in either direction, there's no center equilibrium, if that makes sense

    To compare this with the previous code - drop it onto a clip sitting in the center of your stage.

    This is turning out to be a real "math puzzler"...

    Code:
    onClipEvent (load) {
    //   _x = random (Stage.width);
       _x = Stage.width;
       speed = 10;
       _root.center = Stage.width / 2;
    }
    onClipEvent (enterFrame) {
       if (_root._xmouse < _root.center)
       {
           endX = Stage.width;
           _x += (endX - _x) / speed;
       }
       else
       {
           endX = 0;
           _x += (endX - _x) / speed;
       }
    }

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