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
2010-01-31 04:35:10
`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
2010-01-31 10:07:04
+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
2010-01-31 08:41:12
+1 But note that this won't list private/protected properties/functions of the object.
Amarghosh
2010-01-31 10:10:55