在 Actionscript 2 中创建具有动态键的关联数组
对于 XML 文件,我想在 ActionScript 中创建一个数组,在其中我可以使用我设置的键而不是 0、1、2 等引用特定值,
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
}
以便我可以在以后访问数据,如下
// building description
trace( aBuildings[BUILDING1][property2] );
所示 :不工作 - 我错过了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先将 aBuildings 变量实例化为对象而不是数组:
接下来,您需要首先为要在其中存储属性的键创建一个对象。
然后您应该能够从 aBuildings 对象中读取值:
请记住,如果 BUILDING1 和 property2 不是字符串变量,您需要使用字符串文字。
I would start by instantiating my aBuildings variable as an Object rather than an Array:
Next, you need to create an Object first for the key in which you want to store the properties.
Then you should be able to read the values from the aBuildings object:
Keep in mind that if BUILDING1 and property2 are not String variables you need to use String literals.