How to I change a variable to a Boolean Value? What is a Boolean Value?
A Boolean is a value that is either True or False.
Translate True and False into numbers and you get False = 0, and True = 1.
Flash had a built in Method that will change a variable to a Boolean. Here is some sample code on how to implement that;
var myVariable:Boolean = Boolean(myValue);
This converts the value of “myValue” into a Boolean and stores it as a Boolean value in a variable called myVariable.
Now, what if the value of the variable “myValue” is a string? Well that will store “NaN” in myVariable. NaN translates into “Not a Number”. A string value can’t be change into a Boolean value.
Here are a couple more examples;
var mySample:Boolean = Boolean(123);
var mySample:Boolean = Boolean(0);
The first value evaluates to “True” because any number greater than one will evaluate to “True”. The second value will evaluate to False.
You may notice when I am defining these variables, the format looks like this – var mySample:Boolean. But you don’t know why you are adding a “:Boolean” after the name of the variable. This is data typing. You are defining the type of variable data that can be stored in this variable.
I hope to explain this in a little more depth in the near future.
Posted by jerothe in