Quick introduction to Flash 10’s built-in 3D


November 10th, 2009

At Microsoft, we’ve been re-working some of our Papervision3D projects into the internal Flash 10 way, and I must say for certain things, it is much better than the external 3D libraries out there. Two of our projects (the unreleased PageCUBE and The Interactive Panel) have benefited big-time! The PageCUBE’s file-size dropped 90% after moving away from the Papervision library.

You can’t do everything with Flash 10’s built-in 3D that you can do with the external 3D libraries, but it’s getting close!

Take a gander at the following video from AdobeTV, I’ve also attached some more resources below.

More resources:

Check out the Adobe Language Reference on the DisplayObject class, this is where all of the new 3D stuff exists.

The new properties are:

  • rotationX : Number
    Indicates the x-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
  • rotationY : Number
    Indicates the y-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
  • rotationZ : Number
    Indicates the z-axis rotation of the DisplayObject instance, in degrees, from its original orientation relative to the 3D parent container.
  • scaleZ : Number
    Indicates the depth scale (percentage) of an object as applied from the registration point of the object.

  • z : Number
    Indicates the z coordinate position along the z-axis of the DisplayObject instance relative to the 3D parent container.

The new methods are:

  • globalToLocal3D(point:Point):Vector3D
    Converts a two-dimensional point from the Stage (global) coordinates to a three-dimensional display object’s (local) coordinates.

  • local3DToGlobal(point3d:Vector3D):Point
    Converts a three-dimensional point of the three-dimensional display object’s (local) coordinates to a two-dimensional point in the Stage (global) coordinates.

Z-Sorting

The Z-Index represents the Layers in 3D space. Whatever has a higher z-index is on top.

If you are going to be constructing multiple objects in 3D space with Flash, I highly recommend you download the source files from the GotoAndLearn.com tutorial on the 3D Carousel. You only need the files in com.theflashblog.fp10 called SimpleZSorter.as. This file takes care of the z-sorting in your 3D space. Whatever object is closer to the user, is automatically put to the top of the z-index. It’s an extremely useful tool (Thanks Lee!).

To use it, just import the class, and run a loop (while your 3D objects are moving or changing) that does the sorting:

import com.theflashblog.fp10.SimpleZSorter;
addEventListener(Event.ENTER_FRAME, zSortLoop);
function zSortLoop(e:Event):void {
    // container is the DisplayObject that is the parent of the 3D Objects.
    SimpleZSorter.sortClips(container);
}

Don’t forget to removeEventListener() on the zSortLoop when you are not changing the 3D Objects. This is a best practice that should always be followed…never leave loops running unless they are being used.


Related Posts

One Response to “Organizing dynamically created DisplayObjects with Arrays”

  1. Daniel says:

    Great list – very useful! Compliments to yourself and Adrian Parr.

Leave a Reply