将XML数据解析为多维数组时出错

时间:2020-12-08 21:37:29

i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data to Multi dimensional array, below is the onComplete handler which is succesfully tracing 'event.target.data' but outputs 'A term is undefined and has no properties' when tracing _vein_data[0][0].xPos . I'm guessing there is a easier way to approach it than this attempt

我仍然从as2过渡到as3,我在解析XML数据到多维数组时遇到了麻烦,下面是onComplete处理程序,它成功地跟踪'event.target.data'但输出'一个术语未定义且没有跟踪_vein_data [0] [0] .xPos时的属性。我猜测有一种比这种尝试更容易接近它的方法

private function on_xml_completed(event:Event):void {
   var XMLPoints:XML = new XML(event.target.data);

   for ( var i:int = 0; i < XMLPoints.shape.length(); i++ )
    {
     var shapeArray:Array = new Array();
 _vein_data.push(shapeArray);

    for ( var j:int = 0; j < 4; i++ )
    {
  _vein_data[i].push({'xPos':XMLPoints.shape[i].point[j].@xPos,
          'yPos':XMLPoints.shape[i].point[j].@yPos});
 }
}


 trace(_vein_data[0][0].xPos)
   loadAsset();
  }

here's a portion of my XML;

这是我的XML的一部分;

<items>
 <shape>
  <point xPos="60" yPos="23" />
  <point xPos="65" yPos="23" />
  <point xPos="93" yPos="85" />
  <point xPos="88" yPos="87" />
 </shape>
 <shape>
  <point xPos="88" yPos="87" />
  <point xPos="92" yPos="83" />
  <point xPos="145" yPos="174" />
  <point xPos="138" yPos="175" />
 </shape>
 <shape>
  <point xPos="138" yPos="175" />
  <point xPos="143" yPos="171" />
  <point xPos="147" yPos="211" />
  <point xPos="141" yPos="212" />
 </shape>
</items>  

thank you in advance for any guidance on this Cam

提前感谢您对此Cam的任何指导

1 个解决方案

#1


0  

ok resolved, the problem was the incremented i on the nested for loop, instead of j++;

ok解决了,问题是嵌套for循环中的增量i,而不是j ++;

my bad.

#1


0  

ok resolved, the problem was the incremented i on the nested for loop, instead of j++;

ok解决了,问题是嵌套for循环中的增量i,而不是j ++;

my bad.