A 3D Cube

Flash CS4 supports many new ActionScript 3 classes and methods. In particular, it provides methods that make manipulating objects in 3D much easier. Flipping images, text fields, and other flat display objects has become very simple. See our Player 10 tutorial: 'Getting Started with 3D Methods in Flash Player 10'. (Use Beta 2 versions.) Dynamic drawing in 3D is much easier, too, altough it does require the use of Matrix3D and Vector3D classes. This tutorial covers basics of dynamic drawing in Flash CS4 done in the simplest possible way.

Download

The 'fla' file linked above is exhaustively commented. The simple 3D engine provided in the file can be used for a cube as well as other surfaces. All you need to change is the coordinates of the vertices and the definition of the faces that correspond to your surface.

All the code is attached to the first frame on the Timeline for maximum simplicity.

Note:  This tutorial has some similarities with our very populr tutorial: 'Simple 3D Drawing in Flash CS3'. There are siginficant differences, however:

  • In the Flash CS3 version, we were moving the camera vertically and horizontally while the object remained stationary. Here we are rotating objects about x, y, and z axes.
  • In the Flash CS3 version, the vertical axis remained vertical. In other words, we didn't rotate about the z axis.
  • In the Flash CS3 version, all matrix calculations were perfomed directly as they were no 3D methods available in Flash Player 9.

Overall, the rendering technique presented here is simpler and more flexible. It requires, however, Player 10. If you'd like to be backwards compatible, you may want to use the Flash CS3 version, which, of course, works just fine in Flash CS4 and FP10 as well as in FP9.

On the next page, we use our mini 3D engine to render an icosahedron.

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.