I use this pattern to test for undefined and null values in ActionScript/Flex :
if(obj) {
execute()
}
Unfortunately, a ReferenceError is always thrown when I use the pattern to test for child objects :
if(obj.child) {
execute()
}
ReferenceError: Error #1069: Property child not found on obj and there is no default value.
Why does testing for child objects with if statements throw a ReferenceError?
Thanks!
You’re getting this error because the obj’s type does not have the child property in it. You need to do something like this:
More info on the hasOwnProperty method in the Object class:
http://livedocs.adobe.com/flex/3/langref/Object.html#hasOwnProperty%28%29