Movement towards a target
Code Actionscript 2.0
Instance action
onClipEvent(load) {
targetx=300;
targety=140;
}
onClipEvent (enterFrame) {
this._x = this._x + (targetx - this._x) / 4.0;
this._y = this._y + (targety - this._y) / 4.0;
}
Code Actionscript 3.0
addEventListener(Event.ENTER_FRAME, enterFrame); var targetx=300; var targety=140; function enterFrame(event: Event){ square.x = square.x + (targetx- square.x)/ 4.0; square.y = square.y + (targety- square.y)/ 4.0; }
Description
With this script, the square moves directly towards a target, given by coordinates targetx, targety. The divisor 4.0 determines the smoothness of this movement. A larger number will result in a smoother transition.
related to:
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File