If/Else Tests
by ilyas usal
There's a very useful shortcut in if...else tests when you test whether a
variable equals 0 or not. But you have to know how to use the ! operator. This
operator is used to invert a boolean.
What does that mean? It means that if you have:
myBool = true;
trace (!myBool);
It is also used to test the inequality between two numbers, objects...
Remember that in Flash, 0 is equivalent to false, and any other number is
considered as true.
myValue = 5;
if (myValue != 0)
{
trace ("myValue is not 0");
}
Now to test whether a number is or isn't equal to 0, instead of doing:
if (myValue == 0) //...
if (myValue != 0) //...
You can do respectively:
if (!myValue) //...
if (myValue) //...
Imagine that myValue = 0.
!myValue will be evaluated as true. The same way
if myValue = 5, !myValue
will be evaluated as false.