NEU: Alle Visual Codes als Code Snippets für Flash CS5:
jetzt hier downloaden .

Maus Flucht

Code Actionscript 2.0

Instanz-Aktion

onClipEvent (load) {
startx = this._x;
starty = this._y;
mindistance = 80.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) {
// move away from mouse
this._x = _root._xmouse + (dx * mindistance / distance);
this._y = _root._ymouse + (dy * mindistance / distance);
} else {
// move back to starting point
this._x = this._x + (startx - this._x) / smoothness;
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 mindistance = 80.0; function enterFrame(evet:Event) { var smoothness = 12.0; var dx = square.x - mouseX; var dy = square.y - mouseY; var distance = Math.sqrt(dx * dx + dy * dy); // move away from mouse if (distance < mindistance) { square.x = mouseX + (dx * mindistance / distance); square.y = mouseY + (dy * mindistance / distance); } else { // move back to starting point square.x = square.x + (startx - square.x) / smoothness; square.y = square.y + (starty - square.y) / smoothness; } }

Infos

Das Quadrat weicht der Maus aus, sobald sie näher als mindistance kommt. Andernfalls rutscht es an den Ausgangspunkt zurück.

Download

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


Share