My friends and family are under attack in Ukraine.
Donate to protect them directly or help international organizations.

if (value is Object) problem

January 8th, 2009

To my knowledge, everything is AS3 an object. Functions, Strings, Arrays…

So how do we check if our value is actually an Object? I had this problem in a for loop. I wanted to treat primitive types, Arrays and Objects differently. My first reaction was to test for Arrays, then for Objects and handle the rest in the else block. Well remember that if you check if a String is an Object, you'll get a false positive.

Solution

var className:Object = getQualifiedClassName(value);
if (className == 'Object') {
    // do stuff here
}
else if (className == 'Array') {
    // do stuff here
}
else {
    // do stuff here
}

Previous: Weak Event Listeners Warning Next: Flex Randomness