views:

114

answers:

2

Why does Flex 3 DataGrid read a string from XML lastResult.node as number?

A field is saved as var_char in mysql, php reads it as string and pass it OK. If there are more then 16 charaters it gets rounded....

For example: this in database cell: 12345678901234567 gets read in DataGrid as nubmer as 12345678901234568

this is in database cell: 5555544444222223333377777 php reads it same and puts it in XML flex reads XML into arrayCollection and DataGrid reads it as: 5.55554444422222e+24

So it reads it as number, why? And how to make it read as String?

I tried with labelFunction, no help.

+1  A: 

Because XML is really just a long string of characters, Flex treats them as loosely typed variables, which just really means that flex looks at the data and does it's best to determine what datatype the data is. A simplified version of the logic might go: Any alpha chars in there? then it's a string. All numbers? okay, then it's a number.

I think a way to get around it is to set a variable to a particular type then setting that variable equal to the XML. So in your case instead of

trace(myXML.crazyNumberString);

try

var myValue:String;
myValue = myXML.crazyNumberString;
trace(myValue);

I haven't actually tested this so if that doesn't work try some variations like myValue = myXML.crazyNumberString.toString(); and myValue = myXML.crazyNumberString.toXMLString;

invertedSpear
Thanks for your answer. I found that problem was in using arrayCollection as dataprovider, now with XMLListCollection it works OK!
Nemi
A: 

I found that problem was in using arrayCollection as dataprovider, now with XMLListCollection it works OK!

Nemi