Circle around the mouse

Code Actionscript 2.0

Instance action

onClipEvent(load) {
startx = this._x;
starty = this._y;
mindistance = 160.0;
}

onClipEvent(enterFrame) {
smoothness = 12.0;
dx = this._x - _root._xmouse;
dy = this._y - _root._ymouse;
distance = Math.sqrt(dx*dx + dy*dy);

if (distance < mindistance){
//rotate around mouse
this._x = 2 * startx - _root._xmouse;
this._y = 2 * starty - _root._ymouse;
} else {
// slide back to starting point
this._x = this._x + (startx - this._x) / 12.0;
this._y = this._y + (starty - this._y) / smoothness;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); var startx=square.x; var starty=square.y; var mindistanz=160.0; function enterFrame(event:Event){ var dx = square.x - mouseX; var dy = square.y - mouseY; var distanz = Math.sqrt(dx*dx + dy*dy); //rotate around mouse if (distanz < mindistanz){ square.x = 2 * startx - mouseX; square.y = 2 * starty - mouseY; } else { // slide back to starting point square.x = square.x + (startx - square.x) / 12.0; square.y = square.y + (starty - square.y) / 12.0; } }

Description

The square revolves around the mouse, once it is within the minimum distance [mindistance].

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share