Oscillating movement

Code Actionscript 2.0

Instance action

onClipEvent (load) {

center = 200;

angle = 0;

radius = 80;

speed = 10;

}

onClipEvent (enterFrame) {

angle = angle + speed;

this._x = center + Math.sin(angle * Math.PI / 180) * radius;

}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); var center = 200; var angle = 0; var radius = 80; var speed = 10; function enterFrame(event:Event){ angle= angle+ speed; square.x = center + Math.sin(angle* Math.PI / 180) * radius; }

Description

With this script, the square oscillates horizontally, setting the foundation for a circular movement. The variable angle is set to 0 in the beginning, as it is then increased incrementally. The square now oscillates according to the sin-function. The properties of the osillating movement are determined by the variables center, radius and speed.

related to: Circular movement

Download

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