topical media & game development

talk show tell print

object-ax-oval.ax

object-ax-oval.ax (swf ) [ flash ] flex


  package
  {
          import flash.display.Sprite;
          import flash.events.Event;
          
          public class @ax-object-ax-oval extends Sprite {
                  public var ball:object_ax_ball;
                  private var angle:Number = 0;
                  public var centerX:Number = 200;
                  public var centerY:Number = 200;
                  public var radiusX:Number = 200;
                  public var radiusY:Number = 100;
                  public var speed:Number = .1;
                  
                  public function adjust(s:Number):void {
                   ball.scaleX = s;
                   ball.scaleY = s;
                   }
  
                  public function @ax-object-ax-oval()        {
                          init();
                  }
                  private function init():void {
                          ball = new object_ax_ball();
                          addChild(ball);
                          ball.x = 0;
                          addEventListener(Event.ENTER_FRAME, onEnterFrame);
                  }
                  public function onEnterFrame(event:Event):void {
                  // the book seems to make a mistake here
                          // ball.x = centerX + Math.sin(angle) * radiusX;
                          // ball.y = centerY + Math.cos(angle) * radiusY;
                          ball.x = centerX + Math.cos(angle) * radiusX;
                          ball.y = centerY + Math.sin(angle) * radiusY;
                          angle += speed;
                  }
          }
  }
  


(C) Æliens 20/2/2008

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.