TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

# Planetary Orbits: Elliptical Animations with ActionScript  : Page 3

## Bringing some degree of realism to a simulation of planetary orbits requires elliptical, not circular, paths. This article will show you how to create them. Also included is a major execution order "gotcha" that you may not be aware of!

 by Rich Shupe
 Jul 25, 2005
 Page 3 of 3

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

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!

Rich Shupe is president of FMA, a full-service multimedia development and training facility based in New York. He is a regular Flash columnist for DevX and coauthor of the upcoming "Flash 8: Projects for Learning Animation and Interactivity" and the upcoming "Learning ActionScript 3.0," (both published by O'Reilly). FMA develops web and disc-based products for clients including McGraw-Hill, Phillips, 20th Century Fox, and Nickelodeon, and trains digital media professionals in Flash, ActionScript, HTML, JavaScript, and more.
Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.

Thanks for your registration, follow us on our social networks to keep up-to-date