topical media & game development

talk show tell print

lib-flex-animation-code-07-Test3D.ax

lib-flex-animation-code-07-Test3D.ax (swf ) [ flash ] flex


  package {
          import flash.display.Shape;
          import flash.display.Sprite;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;
          import flash.events.Event;
          import flash.geom.PerspectiveProjection;
          import flash.geom.Point;
          
          public class @ax-lib-flex-animation-code-07-Test3D extends Sprite
          {
                  private var _shape:Shape;
                  
                  public function @ax-lib-flex-animation-code-07-Test3D()
                  {
                          stage.addEventListener(Event.RESIZE, onResize)
                          stage.align = StageAlign.TOP_LEFT;
                          stage.scaleMode = StageScaleMode.NO_SCALE;
                          
                          _shape = new Shape();
                          _shape.graphics.beginFill(0xff0000);
                          _shape.graphics.drawRect(-100, -100, 200, 200);
                          _shape.x = stage.stageWidth / 2;
                          _shape.y = stage.stageHeight / 2;
                          addChild(_shape);
                          
                          addEventListener(Event.ENTER_FRAME, onEnterFrame);
                  }
                  
                  private function onResize(event:Event):void
                  {
                          root.transform.perspectiveProjection.projectionCenter = new Point(stage.stageWidth / 2, stage.stageHeight / 2);
                          if(_shape != null)
                          {
                                  _shape.x = stage.stageWidth / 2;
                                  _shape.y = stage.stageHeight / 2;
                          }
                  }
                  
                  private function onEnterFrame(event:Event):void
                  {
                          _shape.rotationY += 2;
                          _shape.x = stage.stageWidth / 2;
                          _shape.y = stage.stageHeight / 2;
                  }
          }
  }
  


(C) Æliens 18/6/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.