Set XML .@<index> based on interator AS3

Viewed 59

In AS3 is it possible to export multiple iterations of the same variable as seen in the below example:

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 Answers

Haven't worked on AS3 for a while now, but if I remember correctly you should be able to do:

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

Sorry, I don't have tools available to try it out myself, but should work.

Related