In the weeks before my workshop at Multi-mania (getting up to speed with native 3D) I spend a lot of time experimenting with some new api’s. One thing that I kinda needed from the start is a decent rotation class to rotate an object in 3D (at runtime). So I set off and create 2 classes to do just that. The classes are called XYGizmo and YGizmo and they are easy to install even for a non actionscript developer.
As the name already mentions, the XYGizmo allows you to rotate the object in all directions, while the YGizmo only rotates the object around the Y-axis.
Here are some examples, read on for the implementation.
XYGizmo: rotate the plane on both axis by clicking anywhere on the stage and start dragging.
XYGizmo: rotate the expanded cube on both axis by clicking anywhere on the stage and start dragging.
YGizmo: rotate the cube on it’s Y-axis by clicking anywhere on the stage and start dragging.
So how to use it?
1. Download and put the ‘be’ and ‘com’ folder in your project directory
2. Add the import statement. This is either be.multimediacollege.utils3D.XYGizmo or be.multimediacollege.utils3D.YGizmo
3. Call the init function. the first parameter is your interactive object. This object will be used to catch the mouseEvents for the rotation. You can basically use any interactiveobject. If you want to use the whole stage, remember to add stage as the interactive object, passing this will not work on the whole stage, it will only respond on the contents of this (in the example above that’s the whole cube).
The second parameter is the object you want to rotate in 3D.
import be.multimediacollege.utils3d.XYGizmo; XYGizmo.init(stage, plane_mc);
or
import be.multimediacollege.utils3d.YGizmo; YGizmo.init(stage, plane_mc);
This example uses another object as interactive gizmo.
By default, depth sorting is enabled on the target object. To fix the depth sorting in flash, I used Ralph Hauwert’s SimpleZSorter class. That’s why you also need to copy the com folder in your project
Parameters
- Change the speed of the rotation by changing the XYGizmo.speed parameter. By default it’s set to .5; decreasing will lower the rotation speed so you have to move with the mouse more than with a higher value.
- Change the target at runtime by assigning a new displayObject to XYGizmo.target
Change the target by clicking on a square and start dragging.
- set the boundaries to the interactive object by setting the XYGizmo.bounds to true
Dragging will only work when the mouse is over the interactive object
Source files and code library can be found here
Have fun

[...] This post was mentioned on Twitter by tony murphy, MojoGeeks. MojoGeeks said: 3D rotation at runtime with 2 lines of code: In the weeks before my workshop at Multi-mania (getting up to speed w… http://bit.ly/a0FfbN [...]