In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Hooke's Law 2

Get Adobe Flash player
by Tosakun.Meeting 30 Dec 2011
    Embed
/**
 * 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/pix0
 */

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



  public class HookeMoving extends Sprite{
                      private var _xPos:Number = 20; 
                      private var _yPos:Number=0; 
                      private var _tension:Number=0.5;
                      private var _damp:Number=0.95;
                      private var _xTarget:Number=200;
                      private var _yTarget:Number=200;
                      private var _ball:Sprite;
                      

              public function HookeMoving(){
                      this.drawMe();
                      this.setPosition(0,200);
                      var timer:Timer  = new Timer(50,0);
                      timer.addEventListener("timer",HookesMove);
                      timer.start();
              }
             public function setPosition(x:Number,y:Number):void{
                     this._ball.x=x;
                     this._ball.y=y;
             }

             private function drawMe():void{
                   
                    this._ball=new Sprite();
                   
                        this._ball.graphics.beginFill(0x00FF00,200);
                        this._ball.graphics.drawCircle(0,0,10);
                        this._ball.graphics.endFill();
                        addChild(this._ball);
             }
             
            private function HookesMove(e:TimerEvent):void{
                 var ax:Number=(this.mouseX- this._ball.x) * this._tension;
                 var ay:Number=(this.mouseY- this._ball.y) * this._tension;
                 this._xPos+=ax;
                 this._yPos+=ay;
                 this._ball.x+=this._xPos;
                 this._ball.y+=this._yPos;
                 this._xPos*=this._damp;
                 this._yPos*=this._damp;
            }
  }
}