How do I delete a value from an Object-based associative array in Flex 3?

大兔子大兔子 提交于 2019-12-22 05:31:54

问题


I need to remove the value associated with a property in a Flex 3 associative array; is this possible?

For example, suppose I created this array like so:

var myArray:Object = new Object();
myArray[someXML.@attribute] = "foo";

Later, I need to do something like this:

delete myArray[someXML.@attribute];

However, I get this error message at runtime:

Error #1119: Delete operator is not supported with operand of type XMLList.

How do I perform this operation?


回答1:


delete doesn't do as much in AS3 as it did in AS2:

http://www.gskinner.com/blog/archives/2006/06/understanding_t.html

However, I think your problem might be solved by simply using toString(), i.e.

var myArray:Object = new Object();
myArray[someXML.@attribute.toString()] = "foo";

delete myArray[someXML.@attribute.toString()];



回答2:


Rather than delete it, try setting the value to null.

myArray[someXML.@attribute] = null;

That way it'll end up the same as any other value in the array that isn't defined.



来源:https://stackoverflow.com/questions/1155423/how-do-i-delete-a-value-from-an-object-based-associative-array-in-flex-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!