Please I need someone who knows Actions Script to explain me this problem. The code its taken from a tutorial of this page (http://www.kirupa.com/developer/mx/circular.htm):
onClipEvent (load) {
var radius = 10 + Math.random() * 50;
var speed = 5 + Math.random() * 20;
var xcenter = this._x;
var ycenter = this._y;
var degree = 0;
var radian;
}
onClipEvent (enterFrame) {
degree += speed;
radian = (degree/180)*Math.PI;
this._x = xcenter+Math.cos(radian)*radius;
this._y = ycenter-Math.sin(radian)*radius;
}
I know this should be very basic and easy code for most of you, but I’m just learning AS. Well here is the doubre:
In the firs part of que code (the “onClipEvent (load)” part) I wrote some variables, these are not doing anything but getting some random numbers, the x and y values and giving “0” to “degrees” var. (About the “radian” variable I think it’s 0 too, becuase it doesn’t have and “=” simbol).
Well, the doubts came in the second part. Firstable Im saying:
“degree += speed” I understan this should read like:
“degree = degree + speed” In this particular case it should be:
“degree = 0 + random number” In the end this line should drop a number like: 55.2845 or wathever… So why in the second line:
[FONT=Courier New][/FONT]
[FONT=Courier New]“radian = (degree/180)[SIZE=2][COLOR=#000080]Math.PI[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=black];" [/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black]If I repleace the “degree” var for a number:[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black]"radian = ([FONT=Verdana]55.2845[/FONT]/180)[FONT=Courier New][SIZE=2][COLOR=#000080]Math.PI[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=black];”[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black][FONT=Courier New][SIZE=2][COLOR=black][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=black][FONT=Courier New][SIZE=2][COLOR=black]All the code become usless, (the final circular movement wich its the objetive of the tutorial dosent work) ???
And well, in the line:
“this._x = xcenter+Math.cos(radian)*radius;”
Why I have to multiply “Math.cos” with “Radian”?.. Why if I use a simple number instead of the radian var it doesn’t work?
I prove this code without the “Math.PI” function and without multiplying the “radius” in the last two lines and it works perfectly.
I hope somebody can help me with this, Im just traying to understand the code, but I always finish with headaches.
Beforehand Thank You![/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]