Reputation: 11293
for an XML file, I want to create an array in actionscript where I can reference a particular value with a key I set rather than 0, 1, 2 etc
buildings = myParsedObjectFromXML;
var aBuildings = new Array();
for ( building in buildings ) {
var currentBuilding = buildings[building][0];
var key:String = currentBuilding.buildingCode;
aBuildings[key][property1] = currentBuilding.someOtherValue;
aBuildings[key][property2] = currentBuilding.aDifferentValue;
... etc
}
So that I can access the data at a later date like this:
// building description
trace( aBuildings[BUILDING1][property2] );
but the above isn't working - what am I missing?
Upvotes: 0
Views: 4455
Reputation: 21236
I would start by instantiating my aBuildings variable as an Object rather than an Array:
var aBuildings = new Object();
Next, you need to create an Object first for the key in which you want to store the properties.
aBuildings[key] = new Object();
aBuildings[key]["property1"] = currentBuilding.someOtherValue;
aBuildings[key]["property2"] = currentBuilding.aDifferentValue;
Then you should be able to read the values from the aBuildings object:
trace( aBuildings["BUILDING1"]["property2"] );
Keep in mind that if BUILDING1 and property2 are not String variables you need to use String literals.
Upvotes: 2