flash on 2012-7-27
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/UPlw
*/
package {
import flash.events.Event;
import flash.display.Graphics;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var a:Sprite;
public var b:Sprite;
public function FlashTest() {
// write as3 code here..
var g:Graphics;
a = new Sprite();
g = a.graphics;
g.lineStyle(1,0);
g.drawCircle(0,0,32);
addChild(a);
b = new Sprite();
g = b.graphics;
g.lineStyle(2, 0xFF0000);
g.drawCircle(0,0,32);
addChild(b);
a.x = 130;
a.y = 30;
b.x = 220;
b.y = 80;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vx1:Number = 0;
public var vy1:Number = 0;
public var vx2:Number = 0;
public var vy2:Number = 0;
public function onEnter(e:Event):void
{
var dx:Number;
var dy:Number;
var mag:Number;
var nx:Number;
var ny:Number;
dx = a.x - b.x;
dy = a.y - b.y;
mag = Math.sqrt(dx*dx+dy*dy);
var rest:Number = 100;
nx = dx / mag;
ny = dy / mag;
vx1 += -nx * 0.1 * (mag-rest);
vy1 += -ny * 0.1 * (mag-rest);
vx2 += nx * 0.1 * (mag-rest);
vy2 += ny * 0.1 * (mag-rest);
vx1 *= 0.9;
vy1 *= 0.9;
vx2 *= 0.9;
vy2 *= 0.9;
vy1 += 0.5;
vy2 += 0.5;
a.x += vx1;
a.y += vy1;
//b.x = mouseX;
//b.y = mouseY;
b.x += vx2;
b.y += vy2;
if (a.y > 300) { a.y = 300; if (vy1 > 0) { vy1 = 0; } }
if (b.y > 300) { b.y = 300; if (vy2 > 0) {vy2 =0;}}
graphics.clear();
graphics.lineStyle(1,0);
graphics.moveTo(a.x, a.y);
graphics.lineTo(b.x,b.y);
}//onenter
}//classend
}