Needed to know the simples way to convert a number from positive to negative or negative to positive in actionscripts. Here it is.
This is a revise to the flash actionscript tutorial on converting negitive numbers to positive numbers.
Now use Abs() function in flash actionscript
The flash Math.abs() method is used to return the absolute value of x. This basically means it returns the distance between 0 and x in flash actionscript.
Although -5 is a negative number, it’s absolute value is the same as 5. This is because -5 has a distance of 5 from x just as 5 has a distance of 5 from x.
Math.abs(-10); // Returns 10
Math.abs(10); // Returns 10
Old Tutorial on Converting Negatives to Positive and Positive to Negative numbers
I needed to know the simples way to convert a number from positive to negative or negative to positive in actionscripts. Here it is:
// convert 100 to negative -100
n = 100;
n = – n;
trace(n);// will = -100
// convert -55 to positive 50
n = -50;
n = – n;
trace(n);// will = 50
This is how it work. Zero minus a positive number = a negative number. And Zero minus a negative number = a positive number.