Ok ... a preloader

division instead of multiplication…

uggg

<~~ slapping self in forhead.

This is what the holidays can do to an already fragile mind.

OOps my bad, my bad. Sorry, I’m dumb LOL.:lol:
then it is bTotal/1024/1024 …at least I think so…
ok so thx for the rounding action but notice that Math.** roundto[/] (that roundto) doesn’t turn in blue but if I put it Math.** r**** then “round” turns blue…
----------another thing----------
I dunno if it’s possible to do it so but…
Is there any way to calculate the angel of an object…
I mean in flash… The center-point is in the middle of the movie and there is a little box.
box._x = 10;
box._y = 20;
ok and then I want to calculate the angle of the objekt from point 0 (center spot). In my example it should be something about ~30 or ~35 degrees… Is there a way to do it?

<EMBED src=“http://www.centerspin.com/download/rotationExample.swf” quality=high bgcolor=#000000 WIDTH=200 HEIGHT=300 TYPE=“application/x-shockwave-flash” PLUGINSPAGE=“http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash”></EMBED>

source at
http://www.centerspin.com/download/rotationExample.fla

There is something wrong with my** bolding** stuff:lol:
anyway the example you gave there it is -180 degrees - 180 degrees.
It’s like
0 = -90
90 = 0
180 = 90
270 = 180/-180

or something like that
------ok but that’s not what I ment-----
I mean The centerspot there is point “0” and there is a box with its x and y values x =10 = 12
And what I want is the degrees of the box’s position from centerpoint… Makes any sense???

There was a tutorial somewhere about it but I just can’t find it anymore…

Well Supra will post in a while and explain how the radians, get transformed into degrees from 0. However, radians is the way that flash reads rotation. It does in fact say “this object is 170 degrees to the right”, or “this object is 50 degrees to the left.”

Once you start doing some serious rotational stuff you’ll realize how easy radians are. They will be second nature to you.

My book says to multiply radians by 180/PI… now I tried to do that with this and it didn’t work. I can show you how to see and make the angle, but I can’t for the life of my figure out the radian/degree translation, and Supra’s already explained it to me once. :slight_smile:

Well we’ll just have to wait around for him to post again…

syko – custom extensions won’t turn blue, they work as well as they’re written. hopefully this one works well. ; ) just make sure you define it before you use it.

to get angles you’re in trig territory, remember math? turns out it’s actually useful. if your point is 10 to the left and 12 up you have a right angle triangle.

tan(theta) = opp/adj
tan(theta) = 12/10 = 1.2
i don’t remember how to write this but:
1.2 inverted tan = theta
in actionscript:
Math.atan(1.2);

BUT WAIT. macromedia anticipated your dilema and has a function that will do just what you’re looking for Math.atan2(y,x) will return (in radians) the angle formed by that slope. so for you (using the variable technique for conversion that i outline below, don’t forget to define todeg somewhere):

 angle = Math.atan2(12,10)*todeg;

upuaut8 – you’re on the money with your conversion b/w radians and degrees. must have been something else breaking it. i originally wrote a short function for converting, but then i saw someone clever keep those values in global variables:

torad = Math.PI/180;
todeg = 180/Math.PI;

then to convert just multiply by the corresponding variable

degrees = rad * _root.todeg;

it’s a little cleaner than writing a function and you only do the calculations once.

upuaut8, since you’ve been doing all that 3d stuff maybe this will interest you. i built it while trying to understand dot products etc…
<EMBED src=“http://members.shaw.ca/rlinton/posts/math.swf” quality=high bgcolor=#FFFFFF WIDTH=600 HEIGHT=300 TYPE=“application/x-shockwave-flash”></EMBED>

Sweet!!! thank you so much. btw your explination this time made more sense to me. I think that I’ve just about got it. I just need to keep remembering that atan2 Math object. :slight_smile:

Supra-are you telling me that I can just calculate the angle by this line of actionscript?

angle = Math.atan2(12,10)*todeg;

I understand that
“angle” is a variable
Math.atan2(); is an action/function something
12,10 are the x and y values
But why do I have tgo multiply it by some “todeg”?
What is that todeg.
anyway if I add this action then I can calculate the angle?

You need to set these variables in your main timeline somewhere, so that latter you can call on them.

torad = Math.PI/180;
todeg = 180/Math.PI;

Then where ever you are using “_rotation”, because it comes out in radians, you just multiply the output with “todeg” to get a degrees output. If you had degrees from some calculation and you needed to turn that back into radians, then you would multiply it by “torad” and you’d end up with that. But you do need to set those two variables first somewhere in the timeline.

upuaut8’s right on the money.

all of flash’s trig functions return values measured in radians, but the _rotation is set via degrees. use these formulas to convert b/w radians and degrees

radians = degrees * Math.PI/180;
degrees = radians * 180/Math.PI;

if you use something over and over again in a script, you should consider making it a function or variable. this makes your script shorter, faster, and usually easier to read.

rather than dividing 180 by Math.PI everytime you convert, why not do that calculation once, store the results in a variable, and access the variable rather than redo the calculation.

// this goes right at the start of your movie, so it’s always accessable
convertToDegrees = Math.PI/180;

// now when you need to find the rotation
degrees = Math.atan2(12,10); // but wait! * degrees* is still in radians!
degrees *= _root.convertToDegrees; // now we have what we need
_root.tank._rotation = degrees;

so i named converToDegrees a little more descriptively, and spread out the calculation over two lines to make it a little clearer, but this is essentially the same script.

cheers.

ok so If I want to calculate the angle of some object on the main timeline then I put the whole function in _root.
As I understand I can do it by these lines of actionscript.

convertToDegrees = Math.PI/180;
degrees = Math.atan2(12,10);
degrees *= _root.convertToDegrees;

Is that right or did I understand something wrong?

my point is to calculate the angle of an object on the main timeline.

As an example.
In the main timeline there is a button and a circle. Then if somebody clicks on the button the circle’s x and y values are turned to random. And the I want to calculate the degrees of the circle from point 0. I hope you got my point already. I explained it over again just in case :slight_smile: .

yup, i think you’ve got it.

but you don’t need to do it in root, you just need to reference the convertToDegrees variable correctly. i will usually put things like that in _root for sake of convenience, but they can be anywhere.

sometimes it makes sense to put them in a custom object. like tools or something:

_root.tools = new Object();
_root.tools.convertToDegrees = Math.PI/180;

then, to convert rads to degs you’d go:

degrees = radians * _root.tools.convertToDegrees;

if you have a lot of tools, this will prevent clutter in the _root timeline.

but the point is, you can put it anywhere. whatever makes sense to you.

Thanx man… Gotta keep these things in mind…

Believe me… if your script doesn’t work, check in this order

  1. “;” semicolons are a pain in the butt. Especially when you learn that simple commands like “if” statements, don’t really need “{” curly brackets, or the semicolon. You start programing without those and you often forget to put them in. Even in the beginning stages it’s hard to tell if you’ve put the right number of those ****ed curl brackets in.
  2. check your naming convention. “_root.” commands are tricky, and I find “_parent.” to be better, but still funny to deal with.

99.99% of your script errors are due to these two things. Never forget grasshopper, “semicolons”'s and “_root.”'s

Ive been searching on how to calculate andlges in flash. I notices all your examples seem to use rotation, but what if it was a simple right angles triangle?


| /
| /
| /
|/

I have the length of all three sides, but i need to figure out the angle of one of these angles. I tried the example above.

convertToDegrees = Math.PI/180;
degrees = Math.atan2(12,10);
degrees *= _root.convertToDegrees;

but it didnt seem to work. And also which side is the 12, and the 10 and does that make a difference?

Thanks -