topical media & game development

talk show tell print

animation-ch03-Distance.ax

animation-ch03-Distance.ax [swf] [flash] flex


  package
  {
   import flash.display.Sprite;
   
   public class @ax-animation-ch03-Distance extends Sprite {
    
    public function @ax-animation-ch03-Distance() {
     init();
    }
  

init(s)


    private function init():void {
     var sprite1:Sprite = new Sprite();
     addChild(sprite1);
     sprite1.graphics.beginFill(0x000000);
     sprite1.graphics.drawRect(-2, -2, 4, 4);
     sprite1.graphics.endFill();
     sprite1.x = Math.random() * stage.stageWidth;
     sprite1.y = Math.random() * stage.stageHeight;
     
     var sprite2:Sprite = new Sprite();
     addChild(sprite2);
     sprite2.graphics.beginFill(0xff0000);
     sprite2.graphics.drawRect(-2, -2, 4, 4);
     sprite2.graphics.endFill();
     sprite2.x = Math.random() * stage.stageWidth;
     sprite2.y = Math.random() * stage.stageHeight;
     
     var dx:Number = sprite1.x - sprite2.x;
     var dy:Number = sprite1.y - sprite2.y;
     var dist:Number = Math.sqrt(dx * dx + dy * dy);
     trace(dist);
    }
   }
  }
  


(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.