Oscillation

by Tosakun.Meeting
♥0 | Line 32 | Modified 2011-04-02 23:05:08 | MIT License
play

ActionScript3 source code

/**
 * Copyright Tosakun.Meeting ( http://wonderfl.net/user/Tosakun.Meeting )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1fE0
 */

package{
    import flash.display.Sprite;
    import flash.events.Event;
          import flash.events.TimerEvent;
          import flash.utils.Timer;

   public class OscillationMoving extends Sprite{
                       private var _xRadius:Number = 100; /**** ****/
                       private var _angle:Number=45; /**** degree ****/
                       private var _yRadius:Number=150;
                       private var _speed:Number=10;

               public function OscillationMoving(){
                       this.drawMe();
                       this.setPosition(0,400);
                       var timer:Timer  = new Timer(50,0);
                       timer.addEventListener("timer",moveMe);
                       timer.start();
               }
              public function setPosition(x:Number,y:Number):void{
                      this.x=x;
                      this.y=y;
              }

              private function drawMe():void{
                     /**** to draw a red circle with 50 pixels radias ****/
                         this.graphics.beginFill(0xFF0000,200);
                         this.graphics.drawCircle(0,0,10);
                         this.graphics.endFill();
              }

             private function moveMe(e:TimerEvent):void{
                 this.x=200+Math.cos(_angle)*_xRadius;
              
                 this._angle+=0.5;
             }
   }
}