AS3 - Check to see if a string is true /false


/ Published in: ActionScript 3
Save to your folder(s)

When receiving data that contains booleans from JSON, MXML and perhaps even XML, Flash thinks the boolean is a string. If you check to see if the boolean is true, it will always be true unless the value you are checking is null or blank. I created a function that checks to see if a string is true/false.


Copy this code and paste it in your HTML
  1. //Recieves a string, checks to see if it is true/false, passes boolean back
  2. function checkBoolean(val:String):Boolean {
  3. if (val.toLowerCase() == "true") {
  4. return true;
  5. } else {
  6. return false;
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.