> is this a bug? a limitation? or its just me?

It's just the way that the casting rules of Ecmascript work.
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Luis 
Eduardo
Sent: Wednesday, April 18, 2007 7:18 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] boolean not casting ok from string




Gordon and Iko and Hilary,
thx for your assist but i am thinking i am not being very clear on my 
previous post. (perhaps my bad english ;)
what i want to do is a typecast from the String "true" to the boolean 
value true.
this is why i cannot just throw the quotes on the assignment var 
btest:Boolean = "true";
i really need to convert a String to their correspondent boolean value.

what you sugest to me is a workaround, rigth? i mean, all the ways to 
do typecast doesn't work. (so my first post).

is this a bug? a limitation? or its just me?

all this is to take a XML attribute (witch comes as String from 
httpservice) and setup a variable in my form. Yeah, there are another 
ways to do this (and i am using they for now) but the class Number() 
works with this kind of typecast... why not Boolean too?
see, this typecast do works for numbers:
var numTest:Number = Number("3.5");
trace("numtest = "+numTest);

but this not to Boolean:
var numTest:Boolean = Boolean("false");
trace("numtest = "+numTest);

best regards and thank you again for your help!!

Luís Eduardo.

Gordon Smith escreveu:

>> how to cast String "true" to Boolean true ?
> 
> The expression s == "true" evalues to the Boolean value true if the 
> String s is "true", and to false otherwise.
> 
> BTW, there is no point in writing
> 
> var btest:Boolean = new Boolean()
> 
> You should just write
> 
> var btest:Boolean = false;
> 
> or
> 
> var btest:Boolean;
> 
> - Gordon
>
> ----------------------------------------------------------
> *From:* flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] 
> *On Behalf Of *Luis Eduardo
> *Sent:* Wednesday, April 18, 2007 4:54 PM
> *To:* flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> *Subject:* [flexcoders] boolean not casting ok from string
>
>
> hi,
>
> this simple code dont work.
>
> var btest:Boolean = new Boolean();
> btest = "true";
> trace("btest = "+btest);
>
> btest = "false";
> trace("btest = : "+btest);
>
> there are a compile warning telling me that: "3590: String used were a
> Boolean value was expected. The expression will be type coerced to 
> Boolean"
> but it is not.
>
> even if i do typecast it wont work:
>
> btest = Boolean("true");
> trace("btest = : "+btest);
>
> or if i typecast with "as".
> btest = ("true" as Boolean);
> btest = ("false" as Boolean);
>
> so i ask: how to cast String "true" to Boolean true ?
> what am i missing???
>
> Luís Eduardo.
>
> 



 

Reply via email to