在 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..
最佳答案
有一段时间没有在 AS3 上工作了,但如果我没记错的话,你应该能够做到:
for (i = 0; i < <length>; ++i) {
var attrName = "s" + i.toString();
child.@[attrName] = String(object.get_sprite(i));
}
抱歉,我没有可供自己试用的工具,但应该可以使用。
关于actionscript-3 - 基于 interator AS3 设置 XML .@<index>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52994876/