【问题标题】:Set XML .@<index> based on interator AS3基于 interator AS3 设置 XML .@<index>
【发布时间】:2019-03-30 09:31:15
【问题描述】:

在 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 和 Haxe 的 (相同书写*) 解决方案。 *忽略child的细微差别。@> =;与 child.set();

标签: actionscript-3 actionscript


【解决方案1】:

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

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

抱歉,我没有可用的工具来亲自试用,但应该可以。

【讨论】:

    猜你喜欢
    • 2011-09-14
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    相关资源
    最近更新 更多