AS: Main
Basic Math
The Math class in Flash consists of a very large set of operators, for calculating values while running the .swf
I'm going to go over some of the more advanced operators here, bitwise operations.
Basic Boolean Arithmatic Operators
Shift Operations
All numbers on your computer are represented as 0's and 1's more on the actual representation in math advanced. for now we need to know of 2 very quick
and very useful operators << and >> , they are "shift left" and "shift right" , we will use them for ultra fast multiplication and devision by
two, they are over 10 times faster then *2 and /2.
<< (bitwise left shift) is used to shift the bits left, for example
2 which is 10
will become 8 which is 1000
when shifted 2 to the left meaning 8 == 2 << 2;
5 which is 101
will become 10 which is 1010
when shifted 1 to the left, since 10==5 << 1;
all you need to really remmember, that you state the number of times you are multiplying by 2
the usage is as following object1 << object2 shifts object1 object2 locations.
if you want to shorten it and assign object1 = object1 << object2 you may use
object1 <<= object2, this will auto asign it to object 1
>> (bitwise shift right) is used for devision I will not bother explaining it since it does THE EXACT OPPISITE OF OBJECT 1.
remmember, this trick does not work on fractions
Strict Equality
you probebly know that 0 == false in flash, and that null is also the same, and true is equal to one and is equal to many other things, sometimes, knowing it is
equal is not enough, we also want to know it is the same type, for that the "===" operator exists, it checks if the object has the same value and is
the same type
false==0 returns true;
false===0 returns false;
pretty simple, yet very useful
Decreasment and Increasment by 1
to decrease a number called "num" by one all you really have to do is write
num--;
to increase it, you write
num++;
this is pretty handy in for loops, you use it alot in them. now there is an often overlooked difference between num++ and ++num, num++ triggers AFTER the
statement where ++num triggers while it, so for example if num is 7 i=num++ will make i 7 too but i=++num will make i8, num becomes 8 in both cases.
That's all for this time, actual boolean math in Math: Advanced.