Math Object

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Math Object Flash 5; can be used when exporting Flash 4 movies

access to mathematical functions and constants
Math.propertyName Math.methodName( )

Properties

E

The constant e, the base of natural logarithms, approximately 2.71828.

LN10

The natural logarithm of 10 (loge10), approximately 2.30259.

LN2

The natural logarithm of 2 (loge2), approximately 0.69315.

LOG10E

The base-10 logarithm of e, approximately 0.43429.

LOG2E

The base-2 logarithm of e, approximately 1.44270.

PI

The ratio of a circle's circumference to its diameter, approximately 3.14159.

SQRT1_2

The reciprocal of the square root of 2, approximately 0.70711.

SQRT2

The square root of 2, approximately 1.41421.

Methods

abs( )

Compute the absolute value of a number.

acos( )

Compute the arc cosine of a number.

asin( )

Compute the arc sine of a number.

atan( )

Compute the arc tangent of a number.

atan2( )

Compute the angle of a point, relative to the x-axis.

ceil( )

Round a number up to the next integer.

cos( )

Compute the cosine of an angle.

exp( )

Raise e to a specified power.

floor( )

Return the closest integer less than or equal to the input.

log( )

Compute the natural logarithm of a number.

max( )

Determine the larger of two numbers.

min( )

Determine the smaller of two numbers.

pow( )

Raise a number to a specified power.

random( )

Retrieve a random floating-point number between 0 and 1.

round( )

Calculate the closest integer to a number.

sin( )

Compute the sine of an angle.

sqrt( )

Compute the square root of a number.

tan( )

Compute the tangent of an angle.

Description

The Math object provides access to built-in mathematical functions (accessed through methods) and constant values (accessed through properties). These functions and constants are used to perform potentially complex calculations with relative ease.

Note that the properties and methods of the Math object can be used in movies exported in Flash 4 format, in which case Flash will approximate the calculations. The resulting values are reasonable approximations, but they are not necessarily identical to the native functions supported in Flash 5 and later. The Flash 4 values are sufficiently accurate for "close-enough" applications, such as graphics display, but are not accurate enough for critical financial or engineering calculations.

Note that the trigonometric functions require angles to be measured in radians, whereas Flash's MovieClip._rotation property is measured in degrees. There are 2figs/u03c0.gif radians in a circle (1 radian is approximately 57.3 degrees). To convert from radians to degrees, use the formula:

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

To convert from degrees to radians, use the formula:

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

Flash automatically converts all Math object constants to literal numbers at compile-time.

See Also

Section 4.1



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net