I know, there are another ways to do this. Anyway this is a simple one.

Create a new ActionScript File, all we need is to write code, so no fla is needed for this purpose.

Main idea is to add new methods than can be called from our main FLA, or any other that you may create. Not all of this methods will be used in our example, but i think is good to share.

Here is it the code:

class Math2 extends Math { static function rndBetween(n1:Number, n2:Number) { return n1+random(n2-n1+1); } static function radToDeg(n:Number) { return n*180/Math.PI; } static function degToRad(n:Number) { return n/180*Math.PI; } static function degSin(n:Number) { return Math.sin(n/180*Math.PI); } static function degCos(n:Number) { return Math.cos(n/180*Math.PI); } static function degTan(n:Number) { return Math.tan(n/180*Math.PI); } static function angleBetweenRad(x1:Number, y1:Number, x2:Number, y2:Number) { return Math.atan2((y1-y2), (x1-x2)); } static function angleBetweenDeg(x1:Number, y1:Number, x2:Number, y2:Number) { return Math.atan2((y1-y2), (x1-x2))*180/Math.PI; } static function distanceBetween(x1:Number, y1:Number, x2:Number, y2:Number) { return Math.sqrt(Math.pow((y1-y2),2)+ Math.pow((x1-x2),2)); } }



The first line means that we are extending the Math class with this new one called Math2. Basically we have functions to calculate Radians-degrees convertions, distance between points, and also angles.

Save the file as Math2.as, use this name or it will refuse to work.

Finally copy the file in the same folder than your Fla development. In the next section we will start playing with balls.