28 May 2007

MathUtilities Class (AS 3)

While the core classes in Flash have most of what I need, I often find myself wishing there were a few extra elements built into those classes.

A couple of years ago I put together a class called Math2. It was an ActionScript 2.0 class that extends the core Math class in Flash. A majority of the methods are based off of functions Robert Penner’s Programming for Macromedia Flash MX. I have since extended this class and converted it to ActionScript.

MathUtilities features include:

- radiansToDegrees
- degreesToRadians
- sinD
- cosD
- tanD
- atan2D
- angleOfLine
- acosD
- asinD
- fixAngle
- cartisianToPolar
- polarToCartisian
- color24
- color32

I also added the following public methods to the class:

- mean
- median
- mode
- range

I have not yet updated the class for ActionScript 3.0, but hope to do so soon. Converting this to AS 3 was easier than I thought seeing as this class isn’t very involved. The link is below. If you find this class useful, feel free to use and distribute this class freely, provided that it is not modified in any way (including removing the header or changing the package path):

- Math 2MathUtilities – ActionScript 3.0

Unfortunately I cannot provide any support for this class so please use the class in your projects at your own risk. If you would like to report any bugs, or have any feature requests, please feel free to post them here. All feedback is welcome.

ActionScript 3.0 Math Utilities Class (was Math2).

Updates
// 16.11.2008 – - – - – - – - – - -
New behaviors added:
- radiansToDegrees
- color24
- color32

Syntax changes:
- minor parameter names
- changed class name to MathUtilities from Math2
- moved the class to the new package ‘com.unended.util’ (from com.unended.core)

Continue Reading