topical media & game development

talk show tell print

#graphic-flex-image-effects-06-Flex-AppendPrependTest.ax

#graphic-flex-image-effects-06-Flex-AppendPrependTest.ax [swf] [flash] flex


  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 @ax-graphic-flex-image-effects-06-Flex-AppendPrependTest extends Sprite {
  
                  
Constructor. Draws four shapes and appends or prepends transform values.

  
                  public function @ax-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.
parameter: color The color of the shape to draw.
returns: 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;
                  }
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.