Mouse pushing
Code Actionscript 2.0
Instance action
onClipEvent (load) {
speedx = 0;
speedy = 0;
}
onClipEvent (enterFrame) {
// continuously slow down speed
speedx = speedx / 1.2;
speedy = speedy / 1.2;
this._x = this._x + speedx;
this._y = this._y + speedy;
}
on (rollOver) {
// direct speed away from mouse
speedx = (this._x - _root._xmouse) * 1.1;
speedy = (this._y - _root._ymouse) * 1.1;
}
Code Actionscript 3.0
square.addEventListener(Event.ENTER_FRAME, enterFrame); square.addEventListener(MouseEvent.MOUSE_OVER, rollOver); var speedx = 0; var speedy = 0; function enterFrame(event:Event) { // continuously slow down speed speedx = speedx / 1.2; speedy = speedy / 1.2; event.target.x = square.x + speedx; event.target.y = square.y + speedy; } function rollOver(e:MouseEvent) { // direct speed away from mouse speedx = (e.target.x - mouseX) * 1.1; speedy = (e.target.y - mouseY) * 1.1; }
Description
When the mouse rolls over the square, it glides in the opposite direction. This movement decelerates by 1.2 times until the square has come to a stop.
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File