March 16, 2009

ActionScript 3: Toggling a Boolean the easy way

This may be common knowledge to some, but I was pretty excited when I realized I didn't need an conditional statement to figure out which direction to toggle a Boolean value. Check it out:

var isTrue:Boolean = true;
isTrue = !isTrue;
trace(isTrue); // prints "false"
isTrue = !isTrue;
trace(isTrue); // prints "true"

Simplicity is your friend.

4 comments:

  1. i actually heard a little noise when reading the code.

    ReplyDelete
  2. This is awesome. Much easier than the whole "if true then make false, else blah blah blah". I don't know why this isn't common knowledge.

    ReplyDelete