 # Ilyamasse question

In your scrolling window tutorial on this site I was wondering if you could explain to me what exactly this part of the code accomplishes?

MovieClip.prototype.move = function () {
dest = _root.xnew ;
pos = this._x ;
vel = (dest-pos)/7 ;
this._x += vel ;
}
I understand technically the code but I don’t understand its purpose exactly. Like this line vel = (dest-pos)/7; why are you dividing by 7, how does it apply. I don’t see how this code apply’s if you could explain this to me it would be great. Thanks Alot

Kyle I am guessing vel stands for Velocity. Which is the speed it goes at. Dividing it by 7 makes it slow down as it reaches the end.

So its like this

Velocity = (destination-position)/7

Then the last part tells the _x coordinate to be the number that Velocity equals.

I hope I am right!

Oh yeah and…

dest = _root.xnew ;
pos = this._x ;

Dest means destination. That is why it is saved in the variable xnew

and Pos means position, which is where the object is currently.

You’re right, lost. The thing is: I want the clip to go to a certain destination (dest) with a decreasing speed. So I get the distance between the clip and the destination, dest-pos, and I increase the position of the clip by a fraction of that distance.

Doing so, you see that on the next enterFrame, dest-pos will have decreased, so you’ll add less and so on and so on, until it reaches the destination.

And 7 is arbitrary. You’re free to change that value to see what it does (1 means direct jump and a big number means no motion).

pom :asian:

That makes perfect sense. I think I am getting the hang of this AS thing:)