So that you don’t have to figure out all the cryptic error messages that are being thrown from Flash 9 and Flex I have decided to compile a list of error messages and what they mean in a practical sense.
TypeError: Error #1010: A term is undefined and has no properties.
What this error means is that you are trying to access a property of an object that isn’t there. This is very common when using Arrays. This error will also pop-up if you are trying to access a property of an Object that has not been assigned/created.
Bad Example 1:
for (var i:uint=0; i<=internalArray.length; i++) {
if (internalArray[i].length > 10){
trace(internalArray[i].length);
}
}
Good Example 1:
The above example will throw the error because you are trying to access 1 extra element on the end of your array. Just remove the final loop by removing the “=” sign in the comparison. Because Arrays are “0 based” i<=internalArray.length will take you beyond the last index of the array and try and evaluate for a value that is not there. For example var newArray:Array = [“Bob”, “Joe”, “Jim”]; has a length of 3 but Jim has an index of 2.
for (var i:uint=0; i<internalArray.length; i++) {
if (internalArray[i].length > 10){
trace(internalArray[i].length);
}
}
Bad Example 2:
for (var i:uint=0; i
10){
trace(internalArray[i].bob);
}
}
Good Example 2:
The above example will not work because the property bob has not been defined anywhere in the code. You can remedy this by removing the reference to “bob” or by declaring what the “bob” property for each item in the array.
for (var i:uint=0; i
10){
trace(internalArray[i]);
}
}
Bad Example 3:
This example tries to access a property that is created(instantiated) a few lines down.
for (var i:uint=0; i
10){
trace(internalArray[i]);
}
}var internalArray:Array = [“bob”,”jim”,”joe”];
Good Example 3:
The order of operation is important because even though Flash/Flex does some “hoisting” you will still get errors if you don’t order things properly.
var internalArray:Array = [“bob”,”jim”,”joe”];
for (var i:uint=0; i
if (internalArray[i].length > 10){
trace(internalArray[i]);
}
}
As always – Happy Flashing