344
Chapter 6: ActionScript Core Classes
Math class
Availability
Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using
approximations and might not be as accurate as the non-emulated math functions that Flash
Player 5 supports.
Description
The Math class is a top-level class whose methods and properties you can use without using
a constructor.
Use the methods and properties of this class to access and manipulate mathematical constants and
functions. All the properties and methods of the Math class are static and must be called using the
syntax
Math.method(
parameter
)
or
Math.constant
. In ActionScript, constants are defined
with the maximum precision of double-precision IEEE-754 floating-point numbers.
Several Math class methods use the measure of an angle in radians as a parameter.You can use the
following equation to calculate radian values before calling the method and then provide the
calculated value as the parameter, or you can provide the entire right side of the equation (with
the angle’s measure in degrees in place of
degrees
) as the radian parameter.
To calculate a radian value, use the following formula:
radians = degrees * Math.PI/180
The following is an example of passing the equation as a parameter to calculate the sine of a 45º
angle:
Math.sin(45 * Math.PI/180)
is the same as
Math.sin(.7854)
Method summary for the Math class
Method
Description
Math.abs()
Computes an absolute value.
Math.acos()
Computes an arc cosine.
Math.asin()
Computes an arc sine.
Math.atan()
Computes an arc tangent.
Math.atan2()
Computes an angle from the
x
-axis to the point.
Math.ceil()
Rounds a number up to the nearest integer.
Math.cos()
Computes a cosine.
Math.exp()
Computes an exponential value.
Math.floor()
Rounds a number down to the nearest integer.
Math.log()
Computes a natural logarithm.
Math.max()
Returns the larger of the two integers.
Math.min()
Returns the smaller of the two integers.
CHAPTER 6
ActionScript Core Classes
Summary of Contents for FLEX
Page 1: ...Flex ActionScript Language Reference ...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Page 135: ...case 135 See also break default strict equality switch ...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Page 808: ...808 Chapter 7 ActionScript for Flash ...
Page 810: ...810 Appendix A Deprecated Flash 4 operators ...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Page 822: ...822 Index ...