Circular movement

Code Actionscript 2.0

Instance action

onClipEvent (load) {
centerx = 200;
centery = 200;
angle = 0;
radius = 100;
speed = -5;
}
onClipEvent (enterFrame) {
angle = angle + speed;
this._x = centerx + radius * Math.sin(angle * Math.PI / 180);
this._y = centery + radius * Math.cos(angle * Math.PI / 180);
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); var centerx= 200; var centery= 200; var angle= 0; var radius = 100; var speed = -5; function enterFrame(event:Event) { angle= angle+ speed; square.x = centerx+ radius * Math.sin(angle* Math.PI / 180); square.y = centery+ radius * Math.cos(angle* Math.PI / 180); }

Description

This script causes the square to go around in circles. A circular movement is composed of a horizontal and vertical oscillating movement. The angle variable is initially set to 0. Upon loading, it is then incrementally increased by the value of the speed variable. The horizontal and the vertical components are calculated from the sine and cosine of the angle. The parameters of the circular movement are determined by the variables centerx, centery, radius and speed. The angle has to be converted from degree to radians: radian = degree * PI/180

related to: Oscillating movement

Download

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


Share