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";
    • andy
    • June 5th, 2010

    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.

  1. No trackbacks yet.

 

russian brides, sites. . Better way of surveying the market for your auto insurance Provider.

Switch to our mobile site