ABLX
ABLX

Reputation: 736

XML gives me NaN in flex?

Try to read xml data into a variable to put it out in an

xml scheme

<akws>
<akw>
<name>test</name>
<_5>534543</_5>
</akw>
</akws>

now I want the number in <_5> into an s:Label

private function countpop():void{   
popsum = parseInt(xmldata.akw[1]._5);
}

but

<s:Label text={popsum} />

gives me NaN?!

Upvotes: 1

Views: 207

Answers (1)

Jonathan Rowny
Jonathan Rowny

Reputation: 7588

XML is zero indexed and also _5 is an element.

To refer to the int inside _5, use this code:

parseInt(xmldata.akw[0]._5[0]);

Here's my test to confirm:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
    <fx:XML id="xmldata">
        <akws>
            <akw>
                <name>test</name>
                <_5>534543</_5>
            </akw>
        </akws>
    </fx:XML>
</fx:Declarations>
<fx:Script>
    <![CDATA[
        [Bindable]
        private var popsum:int = 0;
    ]]>
</fx:Script>
<s:creationComplete>
    <![CDATA[       
    popsum = parseInt(xmldata.akw[0]._5[0]);    
    ]]>
</s:creationComplete>   
<s:Label text="{popsum}" />
</s:Application>

Upvotes: 3

Related Questions