Scripted motion and inertia
This is the fourth article in the series on creation movement in Flash with ActionScript. So far we’ve looked at moving an object in a straight line and in a circle using ActionScript. We’ve also looked at fading and rotating with code.
In this article, we’ll look at creating more realistic straight line motion. So far, the movement that we’ve created has used a constant speed. This is not very realistic as most of the motion in the real world consists of acceleration and deceleration. When an object moves, there is often inertia slowing it down. If you drove a car without your brakes on, inertia would decrease the speed of the car as you moved further away from your starting point. Similarly, when you drop an object from a height, gravity speeds it up as it gets closer to the ground.
By working through this tutorial, you’ll learn how to add inertia and gravity to your Flash objects. We’ll create functions that allow you to reuse your code throughout your Flash projects.
I've assumed that you are using Flash MX or Flash MX 2004 and that know how to add ActionScript to a movie. I've used ActionScript 1.0 for the examples.
You can download the source files for the tutorial from the blue Properties box that contains the article PDF. There's a heading titled Code Download and you can click the Details link next to it to get the zip file. The download includes the starter files you'll need as well as the completed files.
Note: If you have difficulties downloading the source files or PDF, you might have a problem with your cookies. Delete the cookies from your machine and try again. In Internet Explorer, you can do this by choosing Tools > Internet Options… and clicking the Delete Cookies… button on the General tab.
Read More