根据Interator AS3设置XML。@ <index>

时间:2018-10-25 17:22:28

标签: actionscript-3 actionscript

在AS3中,可以导出同一变量的多个迭代,如下面的示例所示:

var item:String = "obj";
var child:XML = new XML(<{item}/>);
child.@x = String(object.x);
child.@y = String(object.y);
child.@n = String(object.name);
child.@w = String(object.width);
child.@h = String(object.height);

//...instead of:
child.@s = String(object.sprite);

//...is the below possible:
for (i = 0; i < <length>; ++i) {
    child.@s[i] = String(object.get_sprite(i));
}

//...desired <filename>.xml output:
obj.s0 = "sprite_0"
obj.s1 = "sprite_1"
obj.s2 = "sprite_2"
obj.s3 = "sprite_3"
etc..

1 个答案:

答案 0 :(得分:0)

已经有一段时间没有在AS3上工作了,但是如果我没记错的话,您应该可以这样做:

for (i = 0; i < <length>; ++i) {
    var attrName = "s" + i.toString();
    child.@[attrName] = String(object.get_sprite(i));
}

对不起,我没有可用的工具可以自己尝试,但应该可以。