/**
* Copyright Maeda_addevent ( http://wonderfl.net/user/Maeda_addevent )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3pEK
*/
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Point;
[SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
public class FB00004 extends Sprite {
public var sw:Number=stage.stageWidth;
public var sh:Number=stage.stageHeight;
public var max:Number=90;
public var _mySprite:mySprite;
public var _mySprite2:mySprite;
public var _myArray:Array = new Array();
public var _myArray2:Array = new Array();
public var myCol:Array=new Array(0x00FFFF,0x99FF00,0xFF99FF);
public var r:Number;
public var myInt:Number=3;
public var speed:Number=1;
public var dx:Number;
public var dy:Number;
public function FB00004() {
for (var i:Number=0; i<3; i++) {
_mySprite=new mySprite(myCol[i],10);
_mySprite.x = (i+1) * 120;
_mySprite.y=235;
addChild(_mySprite);
_myArray.push(_mySprite);
_myArray[i].addEventListener(MouseEvent.MOUSE_DOWN,xDown);
}
for (var j:Number=0; j<max; j++) {
var _myCol2:Number;
if (j>0&&j<=30||j==0) {
_myCol2=myCol[0];
}
if (j>=30&&j<=60) {
_myCol2=myCol[1];
}
if (j>=60&&j<=90) {
_myCol2=myCol[2];
}
_mySprite2=new mySprite(_myCol2,3);
_mySprite2.x=Math.random()*sw;
_mySprite2.y=Math.random()*sh;
addChild(_mySprite2);
_myArray2.push(_mySprite2);
}
for (var k:Number=0; k<max; k++) {
if (k>0&&k<30||k==0) {
_myArray2[k].addEventListener(Event.ENTER_FRAME,xEnter1,false,0,false);
}
if (k>=30&&k<60) {
_myArray2[k].addEventListener(Event.ENTER_FRAME,xEnter2,false,0,false);
}
if (k>=60&&k<=90) {
_myArray2[k].addEventListener(Event.ENTER_FRAME,xEnter3,false,0,false);
}
function xEnter1(e:Event):void {
r=Math.atan2(_myArray[0].y-e.target.y,_myArray[0].x-e.target.x)*180/Math.PI;
e.target.x+=speed*Math.cos(r/180*Math.PI);
e.target.y+=speed*Math.sin(r/180*Math.PI);
dx=_myArray[0].x-e.target.x;
dy=_myArray[0].y-e.target.y;
if ((Math.abs(dx)<2) && (Math.abs(dy)<2)) {
e.target.x=Math.random()*sw;
e.target.y=Math.random()*sh;
}
}
function xEnter2(e:Event):void {
r=Math.atan2(_myArray[1].y-e.target.y,_myArray[1].x-e.target.x)*180/Math.PI;
e.target.x+=speed*Math.cos(r/180*Math.PI);
e.target.y+=speed*Math.sin(r/180*Math.PI);
dx=_myArray[1].x-e.target.x;
dy=_myArray[1].y-e.target.y;
if ((Math.abs(dx)<2) && (Math.abs(dy)<2)) {
e.target.x=Math.random()*sw;
e.target.y=Math.random()*sh;
}
}
function xEnter3(e:Event):void {
r=Math.atan2(_myArray[2].y-e.target.y,_myArray[2].x-e.target.x)*180/Math.PI;
e.target.x+=speed*Math.cos(r/180*Math.PI);
e.target.y+=speed*Math.sin(r/180*Math.PI);
dx=_myArray[2].x-e.target.x;
dy=_myArray[2].y-e.target.y;
if ((Math.abs(dx)<2) && (Math.abs(dy)<2)) {
e.target.x=Math.random()*sw;
e.target.y=Math.random()*sh;
}
}
}
}
public function xDown(e:MouseEvent):void {
e.target.startDrag();
e.target.addEventListener(MouseEvent.MOUSE_MOVE, xMove);
stage.addEventListener(MouseEvent.MOUSE_UP, xUp);
}
public function xMove(e:MouseEvent):void {
e.updateAfterEvent();
}
public function xUp(e:MouseEvent):void {
e.target.stopDrag();
e.target.removeEventListener(MouseEvent.MOUSE_MOVE, xMove);
stage.removeEventListener(MouseEvent.MOUSE_UP, xUp);
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
class mySprite extends Sprite {
public function mySprite(color:uint,radius:Number) {
var g=this.graphics;
g.beginFill(color,1);
g.drawCircle(0,0,radius);
g.endFill();
}
}