Posted By

sweetbabyyoung on 07/30/09


String to boolean as3

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


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

 / Published in: ActionScript 3

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.

  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  


RSS Icon Subscribe to comments
Posted By: mikehins on November 29, 2009

If you are lookin for boolean from an xml file you can also do

var b:Boolean = Boolean(data[0][email protected] == true);

You need to login to post a comment.