package { import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix3D; import flash.geom.Vector3D; [SWF(width=400, height=400, backgroundColor=0xFFFFFF)] /** * Demonstrates how append and prepend can produce differing results * using same initial transforms by drawing multiple planes and appending or * prepending same transform values. */ public class graphic_flex_image_effects_06_Flex_AppendPrependTest extends Sprite { /** * Constructor. Draws four shapes and appends or prepends transform values. */ public function graphic_flex_image_effects_06_Flex_AppendPrependTest() { var shape0:Shape = createShape(0xFF0000); var matrix0:Matrix3D = new Matrix3D(); // append translation then rotation to first shape matrix0.appendTranslation(250, 100, 100); matrix0.appendRotation(45, Vector3D.Z_AXIS); shape0.transform.matrix3D = matrix0; var shape1:Shape = createShape(0x00FF00); var matrix1:Matrix3D = new Matrix3D(); // append rotation THEN translation to second shape matrix1.appendRotation(45, Vector3D.Z_AXIS); matrix1.appendTranslation(250, 100, 100); shape1.transform.matrix3D = matrix1; var matrix2:Matrix3D = new Matrix3D(); // append rotation to both thrid and fourth shapes' matrices matrix2.appendRotation(45, Vector3D.Y_AXIS); var matrix3:Matrix3D = matrix2.clone(); // prepend initial matrix to third shape's matrix matrix2.prepend(matrix0); // APPEND initial matrix to fourth shape's matrix matrix3.append(matrix0); // darw third shape var shape2:Shape = createShape(0x0000FF); shape2.transform.matrix3D = matrix2; // draw fourth shape var shape3:Shape = createShape(0xFF00FF); shape3.transform.matrix3D = matrix3; } /** * Draws a shape of the specified color. * * @param color The color of the shape to draw. * * @return The shape drawn. */ private function createShape(color:uint):Shape { var shape:Shape = new Shape(); shape.graphics.beginFill(color); shape.graphics.drawRect(-100, -100, 200, 200); shape.graphics.endFill(); addChild(shape); return shape; } } }