将 XML 数据解析为多维数组时出错
我仍在从 as2 过渡到 as3,我在将 XML 数据解析为多维数组时遇到问题,下面是 onComplete 处理程序,它成功跟踪“event.target.data”,但输出“A term is undefined and has no”跟踪 _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();
}
这是我的 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>
预先感谢您对此的任何指导 凸轮
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
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;
<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的解决了,
问题是嵌套 for 循环中递增的 i,而不是 j++;
我的错。
ok resolved,
the problem was the incremented i on the nested for loop, instead of j++;
my bad.