开发者

XML gives me NaN in flex?

开发者 https://www.devze.com 2023-03-14 22:24 出处:网络
Try to read xml data into a variable to put it out in an xml scheme <akws> <akw> <name>test</name>

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 i开发者_StackOverflow社区n <_5> into an s:Label

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

but

<s:Label text={popsum} />

gives me NaN?!


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消