Cast XMLNode to Boolean – AS3


I was having a bit of difficulty making an xml node that had a value of true/false be cast properly as a Boolean. Turns out a good method is to when you are setting it, test it against a string value of true. The boolean will only be set to true if the string in your XML file is “true”.

1
2
//Example
var myBoolean:Boolean = XML.isTrueFalse == "true";
Spread the Good Word:
  • Digg
  • del.icio.us
  • Facebook
  • NewsVine
  • StumbleUpon

  1. #1 by andy on June 5, 2010 - 3:41 am

    i came across the same problem, and also found a string comparison to true to be the best way to fix it.

    The reason is, assuming, like me, you were trying to cast the string as boolean something like

    var myBoolean:Boolean = Boolean(XML.isTrueFalse);

    will assign true if any string is present in that xml node.

(will not be published)

Switch to our mobile site