A Planetarium

In this experiment, we examine the ActionScript 3 method 'drawTriangles' which is new to Flash Player 10 and Flash CS4. This method is particularly useful for 3D texture mapping and we use it to create a collection of planets displayed below. Click on the image to open the applet in a new window.


  • Download all files corresponding to the applet above: cs4planets.zip

All the source files in the package are exhaustively commented. The fla file that corresponds to the 'planetarium' above is cs4planets.fla. The Timeline code in this 'fla' file is quite long because of the many images that are loaded at runtime, radio buttons, and so on. If you like to create your own bitmap sphere, use the file oneplanet.fla contained in the package. The latter file has only one image, stored in the Library. The code is short and easy to customize: you simply replace the image by an image of your choice.

The applet presented here is similar to the applet in our earlier tutorial 'Earth and Other Celestial Bodies in 3D in Flash CS3 and AS3'.

Improvements in Performance:  We have observed significant improvement in performance when 'drawTriangles' is used as opposed to our custom (but standard) AS3 class BitmapTransformer. The latter class was used in the earlier version. Improvements include:

  • Rendering is about 5 times faster;
  • Memory use decreased by about 35 percent;
  • Rendered bitmaps are of higher quality.

Besides the new 'drawTriangles' method, we use the new 3D classes: Matrix3D, Vector3D, as well as the Vector class. We demonstrate the difference between DisplayObject.transform.matrix3D.appendRotation(..) and DisplayObject.transform.matrix3D.prependRotation(..).

We discuss the code on the next page.

Note: The maps of the planets that we used above are courtesy of NASA and JPL-Caltech. They can be found at NASA/JPL-Caltech and Visible Earth.

Back to Flash CS4 Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.