Learn how to interact with Five3D objects.
Interacting with Five3D objects is the same as interacting with any Flash Sprite: you attach event listeners to the various mouse events. The big difference is the Bitmap3D class. Because this extends a Shape, rather than a Sprite, it does not respond to mouse events. This is one of the reasons why the SpriteObject class requires a Sprite and not a DisplayObject, which is the common base class for all the Five3D classes like Bitmap3D, Shape3D and Shape2D.
SpriteMouseObject.as
The SpriteMouseObject class extends the SpriteObject class, and takes care of attaching functions to the more common mouse events. It also takes care of the distinction Flash makes between single and double clicks. If the doubleClick parameter is set to true in the startupSpriteMouseObject function, the Sprites doubleClickEnabled property is set to true and object will respond to the MouseEvent.DOUBLE_CLICK events. Otherwise it will respond to MouseEvent.CLICK events, and double clicks result in two single click events.
Classes that extend the SpriteMouseObject class simply need to call the startupSpriteMouseObject function and override the appropriate functions to respond to mouse events.
BounceOnClick.as
The BounceOnClick class is an example of how to extend the SpriteMouseObject.
The BounceOnClick class will display a Bitmap3D object, so a new instance is created referencing the BitmapData created by the ReosurceManager. [code]
Because the Bitmap3D class does not extend the Sprite class, we can not pass it directly to the startupSpriteMouseObject function. To work around this we create a Sprite3D object, and add the Bitmap3D object as a child. [code]
The Bitmap3D object is then positioned so that its centre is at over the top left corner of the Sprite3D object. We do this because all rotations applied to the Sprite3D are done around the top left corner, and by offsetting the children of the Sprite3D in this way rotations applied to the Sprite3D appear to rotate its children around their centres. Effectively we can define the rotation axis through this parent/child relationship. [code]
The Sprite3D is then positioned according to the parameters that were supplied to the startupBounceOnClick function. [code]
Finally the startupSpriteMouseObject function is called. This will link up all the mouse events, and add the Sprite3D to the scene. [code]
The BounceOnClick class responds to mouse events by overriding the mouseClick function. Here we rotate and scale the Sprite3D using TweenMax. [code]
The two other classes, SpinOnClick and FlipOnMouseOver, work in exactly the same way. The only differences are the mouse functions that they override, and the action that the TweenMax object applies in these mouse functions.
The process of responding to mouse event with Five3D should be familiar to anyone who has worked with the mouse in Flash before; the SpriteMouseObject is simply a convenient way to establish these events and deal with the distinction Flash makes between single and double clicks. Then by using a parent/child relationship with the Five3D objects we can define the rotation axis, allowing us to rotate Five3D objects around their centre, rather than the top left corner.
Go back to Five3D Tutorials
Five3D Tutorials - Drawing 3D Shapes
Learn how to draw Five3D 3D shapes at runtime.
CAKE Programming Tutorial - Mouse Picking
Learn how to select the individual elements that make up a CAKE scene with the mouse.