How to make an object move slowly then stop! ;_;

Hello,

This is my first time to post here… and am new to Flash ^^;;
ummm… i want to make an object that moves horizentally in a movie clip…but I dont know how to make it move slowly then gradually stop…! I tryed playing around with the ActionScript …but no luck ;
; plz help…

Thanks Alot… =)
OniHime

One way to do it is with a simple motion tween. Make sure the object you’re moving is a symbol. In frame 1, place it in the start position. Then place it in the finishing position, however many frames you want later (remembering it’s 12 frames per second). Click on a point in between the start and end, and select Motion Tween from the tween drop down in the Properties panel. Then, you can alter the Easing value in that panel to get it to slow down to a halt gradually.

and the action script solution is also pretty easy. It’s important to note (as you are new) that actionscript can be placed in either a frame, OR attached to an object.

Take the object that you want to move select it.

make sure that it’s a movie clip. If you don’t know, check the properties panel. It should tell you there. If it isn’t one, hit F8 with it selected, then choose movieclip from the dialogue that pops open. Name it whatever you like and hit ‘ok’.

Now that it’s a MC or movie clip, select it, and open the actions panel. The panel should say “object actions” at the top. If it doesn’t you don’t have the object selected.

when you see that, paste this code


onClipEvent(load){
    //change this to where you want the clip to stop
    endLocation=400;
}
onClipEvent(enterFrame){
   diff=endLocation-_x;
    //change the 4 to a higher number to slow, lower number to speed up the effect
   _x+=diff/4;
}

The first part of the code says “when this loads, create a variable called ‘endLovation’ and set it equal to 400.” you can change the 400 to whatever end x location you want.
The second part says "each time this movie clip’s play head enters a frame, do the following: create a variable called diff and set it equal to the difference between endLocation and the current x location of this object, then set the x location of this object to whatever x currently is, plus the diff variable divided by 4;

so if our object is at x location 0, and this script is on it. The math goes like so

it loads on 0, endLocation is 400

diff equals 400 - 0, or 400.
diff is divided by 4 resulting in 100
object is moved along the x axis 100 pixels to the right of it’s current location.

next time around the loop

x location is 100
diff equals 300 (400 - 100)
diff is divided by 4 resulting in 75
object is moved along the x axis 75 pixels to the right of it’s current location

next time around

x location is 175.
diff equals 225

and so on and so on.

for reference… cause it always confused me.
_x by itself is the x location property of the object that the code is attached to. You can set the x by placing it on the left side of an equals sign, or you can read the x property by placing it on the right side of an equals sign.

+=, -=, and *= are shorthand. x+=10 is the same thing as saying x=x+10.

Thanks for your help :slight_smile: it worked… using the tweening and the actionscript…

Now… am trying to do a clip like Kirupa’s infinte menu =)
but…I can’t make the loop work again ;_;… this script works for the slowing down action…but the loop won’t work…

Here’s what I got so far ;_;


onClipEvent (load)
{
   xcenter=100;
   speed=1/10;
}
onClipEvent (enterFrame)
{
   var distance=_root._xmouse-xcenter;
   _x+=(distance*speed);
}

onClipEvent (enterFrame)
{
   var distance=_root._xmouse-xcenter;
   _x+=(distance*speed);
   if (_x > 0) {
	   endLocation=200;
	   diff=endLocation-_x;
      _x+=diff/9; 
	  }
   if (_x < -200) {
	  endLocation = 0;
	   diff=endLocation-_x;
      _x+=diff/9;}
}


Am trying to figure out how to do like the nice footer of moving grassy field of lostinbeta =) hehe … so am playing around with the scripts ^_^;;;;

Thanks again … :slight_smile:
OniHime

*Originally posted by OniHime *
**Am trying to figure out how to do like the nice footer of moving grassy field of lostinbeta =) hehe … so am playing around with the scripts ^_^;;;;

Thanks again … :slight_smile:
OniHime **

Well, this is called easing, there is a tutorial about it already. :slight_smile:

here:

http://www.kirupa.com/developer/mx/followease.asp

yaaay! it worked!! ^^v
hehe… I didnt know that would be called easing ^.^; … its simple too ^
^… playing around with the x axis and the y axis will do the trick :beam:

Thanks so much for the help… all of you =)

^.^

OniHime

What do you need the first enterFrame for? you are doing the same calculation in the second one…oh well…:slight_smile:

yeah, your first (enterframe) is a bit redundant, but oh well, maybe you like to check yourself.