MACROMEDIA FLASH  back to
FLASH 4 TRIGONOMETRIC LIBRARY  

 

flash 4 trigonometric library
flash 4 has very few built-in math functions, so you have to calculate most of them by hand. below you can download a code library to add trigonometric functions to your flash files so you can retrieve the sine, cosine, tangent, secant, cosecant, and cotangent of an angle (in degrees, not radians).

>>download the .fla (zipped)
>>view the demo

usage
here's how to use the trig library in your movies:

  1. copy the "trig library" movie clip to your .fla file.
  2. place an instance of it on the main movie stage, and name it "trig".
  3. set the angle on which to perform your trig function as follows:
    set variable: "/trig:arg" = yourangle
  4. call the function you wish to execute as follows:
    call ("/trig:getSin")
  5. the calculated value will be returned in the variable "output", which is inside the "/trig" movie clip. to retrieve it, use something like this:
    set variable: "var1" = /trig:output
usage note
if you know your angle is between 0 and 360, you can quickly retrieve the sin,cos, or tan, by using this construction: eval ("/trig:sin" & yourangle)

revision history
february 17, 2000: posted.
may 29, 2000: fixed a little bug in cotangent. i was getting cotan 90 by doing 1/tan, but since tan 90 is actually infinity 1/infinity was causing an error, whereas cotan 90 is actually 0. thanks to ben chun over at mit for catching this one...