flash on 2010-1-13
♥0 |
Line 70 |
Modified 2010-02-24 07:47:03 |
MIT License
archived:2017-03-20 12:12:03
ActionScript3 source code
/**
* Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5Lbh
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width=465,height=465)]
public class test extends Sprite{
private var ball:BALL;
private var handls:Array;
private var Numhandls:int=3;
private var spring:Number =0.1;
private var friction:Number =0.95;
public function test(){
init();
}
private function init():void{
ball=new BALL(20);
addChild(ball);
handls=new Array();
for(var i:int=0;i<Numhandls;i++){
var handl:BALL=new BALL(10,0x000000);
handl.x =Math.random()*465;
handl.y =Math.random()*465;
addEventListener(MouseEvent.MOUSE_DOWN,onPress);
addChild(handl);
handls.push(handl);
}
addEventListener(Event.ENTER_FRAME,one);
addEventListener(MouseEvent.MOUSE_UP,up);
}
private function one(event:Event):void{
for(var i:int=0;i<Numhandls;i++){
var handl:BALL =handls[i] as BALL;
var dx:Number =handl.x-ball.x;
var dy:Number =handl.y-ball.y;
ball.vx+=dx*spring;
ball.vy+=dy*spring;
}
ball.vx *=friction;
ball.vy *=friction;
ball.x +=ball.vx;
ball.y +=ball.vy;
graphics.clear();
graphics.lineStyle(1);
for(i=0;i<Numhandls;i++){
graphics.moveTo(ball.x,ball.y);
graphics.lineTo(handls[i].x,handls[i].y)
}
}
private function onPress(event:MouseEvent):void{
event.target.startDrag();
}
private function up(event:MouseEvent):void{
stopDrag();
}
}
}
import flash.display.Sprite;
class BALL extends Sprite{
public var radius:int;
public var color:uint;
public var vx:Number =0;
public var vy:Number =0;
public function BALL(radius:int=10,color:uint=0xff0000){
this.radius =radius;
this.color =color
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}