Environment: Flex 3.6
Look at this piece of code:
var arr:Array = new Array()
var t:Object = {number:"12345", id:"Public"};
arr[t] = "Hello";
for (var z:Object in arr)
{
if (z is String)
trace("STRING");
if (z is Object)
trace("OBJECT");
trace("z.number = " + z.number);
}
output:
STRING
OBJECT
then crashes on the last trace() call with the error:
ReferenceError: Error #1069: Property number not found on String and there is no default value
Isn’t the Object supposed to preserve the name of fields?
What i’m doing wrong?
In the
for(var key)loop for theArrayobjectkeyis alwaysString. You can useDictionarythenkeywill be the type of Object and your code will works: