flash on 2012-6-16
/**
* Copyright Geo877 ( http://wonderfl.net/user/Geo877 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xKai
*/
package {
import flash.display.Sprite;
import flash.events.Event;
public class FlashTest extends Sprite {
public var circle:Sprite = new Sprite();
var circles:Array = new Array();
var circleVX:Array = new Array();
var circleVY:Array = new Array();
var REAL_NUMBER_OF_CIRCLES:Number = 0;
public function FlashTest() {
// write as3 code here..
circle.graphics.beginFill(0xFFEEDD);
circle.graphics.drawCircle(30,40,25);
circle.graphics.endFill();
this.addChild(circle);
var numberOfCircles:Number = 20;
REAL_NUMBER_OF_CIRCLES = numberOfCircles;
while(numberOfCircles>0){
var c:Sprite = new Sprite();
c.graphics.beginFill(0xa4bed4);
c.graphics.drawCircle(0,0,5);
c.graphics.endFill();
c.x = 30+numberOfCircles*10;
c.y = 40+numberOfCircles*10;
circleVX.push(0);
circleVY.push(0);
circles.push(c);
this.addChild(c);
numberOfCircles=numberOfCircles-1;
}
this.addEventListener(Event.ENTER_FRAME,doStuff);
}
public var number:Number = 5;
public function doStuff(e:Event = null):void{
number = number+1;
circle.x = number;
var i:int = REAL_NUMBER_OF_CIRCLES;
while(i>0){
//f=m1 m2 G/r2
var c:Sprite = circles[i-1];
var dx:Number = this.stage.mouseX-c.x;
var dy:Number = this.stage.mouseY-c.y;
var d:Number = Math.sqrt(dx*dx+dy*dy);
var ndx:Number = dx/d;
var ndy:Number = dy/d;
var F:Number = -10/(d*d);
circleVX[i-1] += F*ndx;
circleVY[i-1] += F*ndy;
c.x += circleVX[i-1];
c.y += circleVY[i-1];
i--;
}
}
}
}