Simulating Orbits ... Finally
Again, considering the aforementioned very simplified model, the
source code file "ellipse3_solar_sys.fla" shows how you can set up multiple orbiting bodies. This version of the code adds two things. First, it allows you to pick any spot around which to set up the ellipse. (The previous two examples used the center of the stage.) Second, it allows you to specify this value independently, for each orbiting body. So, for each MovieClip you can specify a point, or another MovieClip, around which to orbit.
To keep the script consistent, this is accomplished by passing either a MovieClip or a point object into the necessary parameter. For example:
setEllipse(mc3, 320, 220, 0, 2, -1, {_x:100, _y:200});
setEllipse(mc2, 35, 30, 0, 10, -1, mc3);
The first line specifies that MovieClip "mc3" orbits point (100,200), while the second line specifies that MovieClip "mc2" orbits the current location of MovieClip "mc3"wherever that may be. This allows you to set up a body that is orbiting another body that is in an orbit of its own (the Moon orbiting the Earth, which is orbiting the Sun). (To save your self a lot of frustration, be sure to read the sidebar, "
Know the Flash Execution Order.")
What's Next, Black Holes?
First and foremost, I hope you came away from this article with an understanding of how to modify a circular orbit into an elliptical orbit. If you think you can set up an elliptical orbit using its center, try using one of the ellipse's focus points. As usual, I'd love to see any experiments that you may come up with!