Archive

Posts Tagged ‘typing’

if (value is Object) problem

January 8th, 2009 9 comments

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
}
Tags: ,

Switch to our mobile site