flash on 2012-5-25
♥0 |
Line 137 |
Modified 2012-06-01 14:11:54 |
MIT License
archived:2017-03-20 15:18:13
ActionScript3 source code
/**
* Copyright jokehn9 ( http://wonderfl.net/user/jokehn9 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/c6mT
*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Shape;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var circle:Shape = new Shape();
circle.graphics.lineStyle(1,0x0);
circle.graphics.beginFill(0x0);
circle.graphics.drawCircle(-30,-30,10);
addChild(circle);
var circle2:Shape = new Shape();
circle2.graphics.lineStyle(1,0x0);
circle2.graphics.beginFill(0x0);
circle2.graphics.drawCircle(-30,-30,10);
addChild(circle2);
var circle3:Shape = new Shape();
circle3.graphics.lineStyle(1,0x0);
circle3.graphics.beginFill(0x0);
circle3.graphics.drawCircle(-30,-30,10);
addChild(circle3);
var ax:Number = 0;
var ay:Number = 0;
var dx:Number = 0
var dy:Number = 0;
var ms:int = 0;
var ax2:Number = 0;
var ay2:Number = 0;
var dx2:Number = 0
var dy2:Number = 0;
var ms2:int = 0;
var ax3:Number = 0;
var ay3:Number = 0;
var dx3:Number = 0
var dy3:Number = 0;
var ms3:int = 0;
var size:int = 40;
addEventListener("enterFrame", loop);
stage.addEventListener(MouseEvent.CLICK,msclick);
function msclick(e:MouseEvent):void {
if(ms == 0) {
dx = 7*(-18 + Math.random()*36)/stage.frameRate*10;
dy = 7*(-18 + Math.random()*36)/stage.frameRate*10;
circle.x = mouseX+dx*3;
circle.y = mouseY+dy*3;
}
ms = 1;
if(ms2 == 0) {
dx2 = 7*(-18 + Math.random()*36)/stage.frameRate*10;
dy2 = 7*(-18 + Math.random()*36)/stage.frameRate*10;
circle2.x = mouseX+dx2*3;
circle2.y = mouseY+dy2*3;
}
ms2 = 1;
if(ms3 == 0) {
dx3 = 7*(-18 + Math.random()*36)/stage.frameRate*10;
dy3 = 7*(-18 + Math.random()*36)/stage.frameRate*10;
circle3.x = mouseX+dx3*3;
circle3.y = mouseY+dy3*3;
}
ms3 = 1;
}
function loop(e:Event):void {
if(ms == 1) {
dx += ax;
dy += ay;
ax = 25*(1/stage.frameRate)*(mouseX - circle.x)/Math.sqrt(Math.pow((mouseX - circle.x),2)+Math.pow((mouseY - circle.y),2));
ay = 25*(1/stage.frameRate)*(mouseY - circle.y)/Math.sqrt(Math.pow((mouseY - circle.y),2)+Math.pow((mouseX - circle.x),2));
circle.x += dx;
circle.y += dy;
if(Math.abs(dx) > 300/stage.frameRate) {
dx *= 0.7;
}
if(Math.abs(dy) > 300/stage.frameRate) {
dy *= 0.7;
}
if(mouseX + Math.abs(dx) + size> circle.x && mouseX - Math.abs(dx) -size < circle.x && mouseY + Math.abs(dy)+size> circle.y && mouseY - Math.abs(dy)-size< circle.y) {
circle.x = -30;
circle.y = -30;
dx = 0;
dy = 0;
ax = 0;
ay = 0;
ms = 0;
}
}
if(ms2 == 1) {
dx2 += ax2;
dy2 += ay2;
ax2= 25*(1/stage.frameRate)*(mouseX - circle2.x)/Math.sqrt(Math.pow((mouseX - circle2.x),2)+Math.pow((mouseY - circle2.y),2));
ay2 = 25*(1/stage.frameRate)*(mouseY - circle2.y)/Math.sqrt(Math.pow((mouseY - circle2.y),2)+Math.pow((mouseX - circle2.x),2));
circle2.x += dx2;
circle2.y += dy2;
if(Math.abs(dx2) > 300/stage.frameRate) {
dx2 *= 0.7;
}
if(Math.abs(dy2) > 300/stage.frameRate) {
dy2 *= 0.7;
}
if(mouseX + Math.abs(dx2) + size> circle2.x && mouseX - Math.abs(dx2) -size < circle2.x && mouseY + Math.abs(dy2)+size> circle2.y && mouseY - Math.abs(dy2)-size< circle2.y) {
circle2.x = -30;
circle2.y = -30;
dx2 = 0;
dy2 = 0;
ax2 = 0;
ay2 = 0;
ms2 = 0;
}
}
if(ms3 == 1) {
dx3 += ax3;
dy3 += ay3;
ax3 = 25*(1/stage.frameRate)*(mouseX - circle3.x)/Math.sqrt(Math.pow((mouseX - circle3.x),2)+Math.pow((mouseY - circle3.y),2));
ay3 = 25*(1/stage.frameRate)*(mouseY - circle3.y)/Math.sqrt(Math.pow((mouseY - circle3.y),2)+Math.pow((mouseX - circle3.x),2));
circle3.x += dx3;
circle3.y += dy3;
if(Math.abs(dx3) > 300/stage.frameRate) {
dx3 *= 0.7;
}
if(Math.abs(dy3) > 300/stage.frameRate) {
dy3 *= 0.7;
}
if(mouseX + Math.abs(dx3) + size> circle3.x && mouseX -Math.abs(dx3) -size < circle3.x && mouseY + Math.abs(dy3)+size> circle3.y && mouseY - Math.abs(dy3) -size< circle3.y) {
circle3.x = -30;
circle3.y = -30;
dx3 = 0;
dy3 = 0;
ax3 = 0;
ay3 = 0;
ms3 = 0;
}
}
}
}
}
}