# Dynamic object naming from xml in array

**URL:** <https://forum.kirupa.com/t/dynamic-object-naming-from-xml-in-array/279953>\
**Category:** flash\
**Created:** [January 21, 2009, 12:13am UTC](https://forum.kirupa.com/t/dynamic-object-naming-from-xml-in-array/279953 "2009-01-21T00:13:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustinbrunson](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dustinbrunson](https://forum.kirupa.com/u/dustinbrunson)\
**Post date:** [January 21, 2009, 12:13am UTC](https://forum.kirupa.com/t/dynamic-object-naming-from-xml-in-array/279953/1 "2009-01-21T00:13:21Z")

</div>

This is the object array target structure I am looking to create

myObject.myArray[0].data=value;  
myObject.myArray[0].data2=value2;  
myObject.myArray[1].data=value;

myObject.anotherArray[0].data=value;  
myObject.anotherArray[0].data2=value2;  
myObject.anotherArray[1].data=value;  
myObject.anotherArray[1].data2=value2;

An Object (myObject) with an Array (myArray) of Objects;

I can do this fine manually, but what I am wanting to do is create this dynamically from xml data. All of which works fine done manually in code. This is my basic dynamic code:

var xml=xmldata;  
do {  
current:Object = new Object(); // the main object  
var name:String=xml.nodeName; // ie - text

```
/// create an array in current with an object inside ie (current.text*.data)
set("current." + name, [{}]); 

var node=xml.firstChild;
var i=0;
do { 
    for (attr in node.attributes) {
        // this is basically what I am trying to replicate
        // current.text[0].attr=node.attributes[attr];
        //or current.text[0].id=16;  
        
        // All the variables work, I just can't get them to be placed inside 
        //the object inside the array
        
        set(current[name+"["+i+"]."+attr], node.attributes[attr]); //no worky

        //current[name+"["+i+"]."+attr]=node.attributes[attr]; //no 
        //this[current+name+"["+i+"]."+attr]=node.attributes[attr]; //nope
    }
    i++;
    
} while (node = node.nextSibling);

```

} while (xml = xml.nextSibling);

Anyone have any suggestions?

Thanks, Dusty
