package { import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix3D; import flash.geom.Vector3D; [SWF(width=700, height=400, backgroundColor=0xFFFFFF)] /** * Demonstrates how decompose/recompose can be used to affect one component of a 3D transform * without being affected by transform's other components' values. */ public class graphic_flex_image_effects_06_Flex_DecomposeRecomposeTest extends Sprite { /** * Constructor. Creates two shapes, then transforms both. For first shape, new scale is directly * appended. For second shape, scale is just added to single scale vector after transform * is decomposed. */ public function graphic_flex_image_effects_06_Flex_DecomposeRecomposeTest() { var shape0:Shape = createShape(0xFF0000); var matrix0:Matrix3D = new Matrix3D(); matrix0.appendTranslation(250, 200, 100); matrix0.appendRotation(45, Vector3D.Y_AXIS); shape0.transform.matrix3D = matrix0; var shape1:Shape = createShape(0x00FF00); // dupe first shape's transform shape1.transform.matrix3D = matrix0.clone(); // append scale to first shape shape0.transform.matrix3D.appendScale(2, 1, 1); // separate all of the transform's components var vectors:Vector. = shape1.transform.matrix3D.decompose(); // alter just the scale vector vectors[2] = new Vector3D(2, 1, 1); // recompose transform with new scale value shape1.transform.matrix3D.recompose(vectors); } /** * Creates a shape of the specified color. * * @param color The color for the shape. * * @return The shape created. */ private function createShape(color:uint):Shape { var shape:Shape = new Shape(); shape.graphics.beginFill(color); shape.graphics.drawRect(-50, -50, 100, 100); shape.graphics.endFill(); addChild(shape); return shape; } } }