错误#1034:无法将XMLList @ c093fd1转换为mx.collections.ArrayCollection

时间:2013-12-26 14:08:07

标签: xml flex

        protected function initView(event:ViewNavigatorEvent):void
            {
                // Api Call
                NFLScore.url="http://api.nfldata.apiphany.com/trial/XML/ScoresByWeek/2013REG/14" +
                    "?key=BDAE4263-4522-45B9-96FF-01F0DFB0F610";
                NFLScore.send();
            }
            protected function NFLScore_resultHandler(event:ResultEvent):void
            {
                // Alle items en Labels value geven

                myData=event.result.ArrayOfScore.Score;

            }
            protected function NFLScore_faultHandler(event:FaultEvent):void
            {
                // TODO Auto-generated method stub
                printUit.text = "foute zoek opdracht";
            }

                                //////// End ////////
            ///////////////////////// API CALL /////////////////////////

        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:HTTPService id="NFLScore" fault="NFLScore_faultHandler(event)" 
                       result="NFLScore_resultHandler(event)" resultFormat="e4x" />
    </fx:Declarations>
    <s:actionContent>
        <s:Button id="Score" icon="assets/Score.png" click="Score_clickHandler(event)" />
    </s:actionContent>

    <s:Label id="printUit"/>
    <s:TextArea height="100%" width="100%" id="txtResult" text="{NFLScore.lastResult.Score.AwayScore}"/>


</s:View>

Result: 

<AwayScore xmlns:i="http://www.w3.org/2001/XMLSchema-instance">20</AwayScore>
<AwayScore xmlns:i="http://www.w3.org/2001/XMLSchema-instance">26</AwayScore>
<AwayScore xmlns:i="http://www.w3.org/2001/XMLSchema-instance">21</AwayScore>

需要: 输出: 20 26 21

情况:我正在调用API,它给我结果(XML)作为主要节点ArrayOfScore之后的那个得分日期是我想要的。但我一直收到错误“TypeError:错误#1034:类型强制失败:无法将XMLList @ c1e1fd1转换为mx.collections.ArrayCollection。”

1 个答案:

答案 0 :(得分:0)

您必须重写下面指定的代码

protected function NFLScore_resultHandler(event:ResultEvent):void
            {
                var obj:SomeObject = null;//someobject is any class that stores the xml data that is returned from the server. 
                for(XML item:event.result.ArrayOfScore.Score){
                      obj = new SomeObject();
                      obj.someProperty = item.toString();
                      myData.additem(obj);
                }
            }

基本上你正在做的是,通过上面的迭代将一个对象(xmllist)类型转换为arraycollection对象。这可能不完美,但是,shoudl会给你一个开始研究它的想法。