if 'boolean == false', can you also check 'boolean == undefined' or 'boolean == null'?
IE: var dog = false;
if (dog == undefined) {}
- or -
if (dog == null) {}
Would either of these check to see if 'dog' is set to 'false'?
no false is an existing deifned variable state, so it is neither null nor undefined.
perhaps I misunderstood.
you can indeed declare:
dog = undefined; if (dog == undefined) {trace("OK")}
dog = null; if (dog == null) {trace("OK")}
dog = false; if (dog == false) {trace("OK")}
Sorry for my lack of clarity. What I am asking is this:
Does can you check for a 'false' value by testing against 'null' or 'undefined'? Perhaps this is a better example:
var dog = false; var cat = null;
if (dog == cat) {}
Would the 'if' statement return a true? It seems as though your first reply answered the initial question. Sorry I lagged in getting back to you, but I was in a meeting.
Per usual, thank you for your help!
No it won't return true because a var declared false is no longer null or undefined, but defined as false, so it does indeed exist.
That is what I had thought, but I was not certain. On a related note, does this work:
if (!dog) {}
to test for 'dog == false'?
I had read somewhere that '!variable' does not work consistantly in Flash.
indeed ! will check for false, null, and undiefined.

_Originally posted by faerieprince _ **That is what I had thought, but I was not certain. On a related note, does this work:
if (!dog) {}
to test for 'dog == false'?
I had read somewhere that '!variable' does not work consistantly in Flash. **
The thread here answeres your questions regarding !variable
http://www.twelvestone.com/forums/showthread.php?s=&threadid=1667
It does work consistantly and is useful once you understand the logic.
i was actually going to offer some thoughts on ! and true/false, then realized that i did so in the thread arsis linked to.
on a side note, another (extremely useful!) use of the ! operator is for creating toggles. let's say you have a boolean that starts at true, and everytime a user hits a button you want to switch it back and forth from true to false to true.....switch = true;
function ToggleSwitch() { switch = !switch; }the function above will always do a logical NOT of the the value of the variable, so if true it becomes false and is false becomes true.
probably my favorite use for ! 
That is pretty smart. I might have to start incorporating that. It is cleaner than my current method of using flags.
Thanks for the idea!
one thing that might help you understand it is thinking in data types. there is a type of data called boolean. it has two values, true and false.
whenever you use a comparator (==, !=, <, >, etc.) the result is a boolean value, it's either true/false. also, the argument for if(...) is a boolean value.
so,
flag=true; if(flag)...
is totally valid, as well as
if(!flag)...
because it's looking for a boolean, and it finds one.
saying
if(flag==true)...
is really overkill.
in most other strictly typed languages, data types are much clearer. a boolean can only accept true/false values, and you'd have to declare the variable as being a boolean. flash is so loose and converts so easily, you can often forget that there are different data types, and think that true/false are just other values.
nice explanation bit.
another thought from that. like said above, the comparison operators return boolean values. because of this it is perfectly acceptable to use them to set a boolean. for example, this codeif (myVar > 5) { isGreater = true; } else { isGreater = false; }can be written out like that (and sometimes should be), but you can accomplish the same thing in one line using the comparisons as booleanisGreater = myVar > 5;the code will execute exactly the same in both examples.