views:

287

answers:

2

Is it possible to check a class to see whether it has a method or not ? Or even a particular property

+2  A: 
import flash.utils.describeType;
...
function methodExists(obj:Object,name:String):Boolean
{
        var desc:XML=flash.utils.describeType(obj);
        return (desc.method.(@name==name).length()>0);
}

(Note: done off the top of my head)

Jason B
`describeType` does not list dynamic properties. Try it on this object for instance: `var target:Object = {a:123, b:"ASD", c:function():void{trace("hello");}}` - outputs the description of a plain object with just `hasOwnProperty`, `isPrototypeOf` and `propertyIsEnumerable`.
Amarghosh
+3  A: 
var target:Object;// = some object
var name:String;// = some name
if(name in target){
    // if property/method exists
}else{
    // if property/method not exists
}
a_w
+1 But note that this won't list private/protected properties/functions of the object.
Amarghosh
yea, i probably wont need it if its private or protected. thanks
numerical25