It is weird, but that what the ECMAScript committee decided.  It is a bit 
inconsistent, but you are actually calling functions and not really casting.  
So you'll have to live with converting as to whether the string == "true"

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Luis 
Eduardo
Sent: Wednesday, April 18, 2007 9:06 PM
To: [email protected]
Subject: Re: [flexcoders] boolean not casting ok from string





yeah shaun, you are rigth. After follow your sugestion i searched in 
the docs and found what you mean here:
http://livedocs.adobe.com/flex/201/langref/package.html#Boolean 
<http://livedocs.adobe.com/flex/201/langref/package.html#Boolean> ()
Boolean its a function that have the same behavior than the Boolean 
constructor that take a non-empty string and convert it to "true".

aww.

very weird.

anyway thank you and the others to help understand what is going on here.
now i will try to minimize the damages :)

[]'s,

Luís Eduardo.

shaun escreveu:

> Hi,
>
> Its not a bug. Note: the Constructor for Boolean in the docs.
> Think about it as if you have the following:
>
> var moo:String = "Moooooooooo";
> if (moo) {
> // have a cow.
> }else{
> //no cow.
> }
>
> So, Boolean("false") is true!
>
> var y;
> var x:Object;
> var b:Boolean = Boolean("false");
> trace("b1 false is "+b.valueOf());
>
> b = 0;
> trace("b2 (0) is "+b.valueOf());
>
> b = 1;
> trace("b3 (1) is "+b.valueOf());
>
> b = 2;
> trace("b4 (2) is "+b.valueOf());
>
> b = -1;
> trace("b5 (-1) is "+b.valueOf());
>
> b = null;
> trace("b6 (explicit null) is "+b.valueOf());
>
> b = x;
> trace("b7 (unassigned null, undef) is "+b.valueOf());
>
> b = y;
> trace("b8 (undef) is "+b.valueOf());
>
> b = (new Object() as Boolean);
> trace("b9 (as not a boolean ie, null) is "+b.valueOf());
>
> ---------------------------------------------------------
> b1 false is true
> b2 (0) is false
> b3 (1) is true
> b4 (2) is true
> b5 (-1) is true
> b6 (explicit null) is false
> b7 (unassigned null, undef) is false
> b8 (undef) is false
> b9 (as not a boolean ie, null) is false
>
> --------------------------------------------------------
>
> HTH,
> shaun
>
> 



 

Reply via email to