.
Actionscript doing simple mathematics
We all either hate or love math, but one thing is for sure, if you want to be a programmer or just do some simple lines of code, you will need to do some math.
Doing math in actionscript is a bit more than just adding and subtracting, like any other programming languages it uses some reserved words to define different mathmathic methods.

I will use the Trace function in flash to output the result, you can always point to a textbox, text field later if you want.
Here is how to just add, subtract, divide and muliply (this is the simple part).
trace(1 + 1); trace(2 - 1); trace(2 * 2); trace(4 / 2);
Note that we work with numbers so no double qoutes, like we do with text.
Now a very useful tool is to type Math. (something) this contains useful functions like ramdom, I will show a couple of examples, they all basically work the same way.
trace (Math.random()); //This outputs a random number less than 1. //Now you might think this outputs a very long 0.00043348 number, here is how to round the number. trace (Math.floor(Math.random() * 10)); //This will output a round number between 1-9 //And if you want two digi numbers do it like this. trace (Math.floor(Math.random() * 100));
Now to combining the calculation and ramdom function.
b = 10 + Math.floor(Math.random()*6); trace(b)
This will give you a random number between 10 and 15, as you see a great tool.
And is you want to do any math on angle calculations, calculate with circles and triangles etc, you will need these function.
trace (Math.cos(1)); trace (Math.tan(1)); trace (Math.sin(1));
I will do more on math with angles later in a bigger project I'm working on, where I will use it to make smaller flash games, this is where the math really gets fun and interesting.
krishna chaitanya sharma says: 2008-02-05
Robert says: 2008-01-06
Admin Bob says: 2008-01-07
Andrew says: 2007-12-29
Er says: 2007-12-28

