Posted By

goatboy91587 on 08/08/10


Tagged

flash


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

donaldleegraham
tspitzr


AS3 Boolean Example


 / Published in: ActionScript 3
 

URL: http://www.brettwidmann.com

Used for the blog post: http://www.brettwidmann.com/2010/08/flash-primitive-data-types

  1. //declare an int with a value of 5 and boolean
  2. var five:int = 5;
  3. var bool:Boolean;
  4.  
  5. if (five > 6)
  6. {
  7. bool = true;
  8. }
  9. else
  10. {
  11. bool = false;
  12. }
  13.  
  14. //when comparing booleans, always make sure to
  15. //use two '=' signs, otherwise you'll set the
  16. //value of the variable to what you are trying
  17. //to compare. This is called a logical operator.
  18. if (bool == true)
  19. {
  20. trace("This should actually be false. The value is 5, " +
  21. "greater than 6.")
  22. }
  23. else
  24. {
  25. trace("The value of the int is 5.");
  26. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: damoq on July 5, 2012

Good snippet for beginners and how to understand how booleans work. More simplified code would be:

bool = (five > 6);

if(bool) {

} else {

}

You need to login to post a comment.