actionscript-3 - 基于 interator AS3 设置 XML .@<index>

标签 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..

最佳答案

有一段时间没有在 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/

相关文章:

android - AS3 Android Air 应用程序,当用户离开应用程序时音乐不会关闭

apache-flex - flex 4 组中的中心元素

android - 什么时候应该在 Flash 中使用 CPU 或 GPU 编译器选项?

flash - 在 Flash 中拍摄显示对象可见区域的快照

actionscript-3 - 弹性单元测试

actionscript-3 - ActionScript3 错误处理 URLRequest

apache-flex - Flex : selectable text in DataGridColumn?

actionscript-3 - AS3 - 距离下一帧/屏幕绘制还有多长时间

iphone - 在 AIR/AS3 中使用特定于移动设备的类测试代码时,如何避免出现VerifyError?

actionscript-3 - 通过代码删除形状