PDA

View Full Version : XML Node and casting to int


hobbis
05-21-2008, 01:32 PM
Just came across a strange behaviour in my Flex app when casting a xml node value to int.



//The attibute is set to '2'

var selectedCodeId:int = int(selectedFilterTreeNode.@codeId); //gave 2

var selectedCodeId:int = selectedFilterTreeNode.@codeId as int; //gave 0


Anyone seen this before?

amarghosh
05-21-2008, 02:32 PM
livedocs:
'as' operator evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. If the first operand is a member of the data type, the result is the first operand. Otherwise, the result is the value null.

here first operand is a string and hence null (i don't know how it became zero)

hobbis
05-21-2008, 02:37 PM
Thanks for the reply. Interesting. Strange one this because I've used in the past without a problem. I'll read more of the docs...