Parse Boolean method for Flex
I wonder why there isn’t an out of the box Boolean parser in Flex, I must have built this same method at least 3 times for different projects… You should probably add this to your utils as well.
static public function parseBoolean(str:String):Boolean {
switch(str) {
case "1":
case "true":
case "yes":
return true;
case "0":
case "false":
case "no":
return false;
default:
return Boolean(str);
}
}
You might want to do a String.toLowerCase() before you start switching.
Also, using enumerations will avoid a lot of headache whenever you’ve the luxury of being able to use them.
It’s not rocket science but it saved me a few minutes of work.
Cheers mate 😉