While looking for a better solution on the same issue I came across this pageref 1: quote: deadlock32
EDIT: use the above, it's way better. ( can't believe i wrote the code below) while referring to the try catch solution on this["methodname"]
ref 2: quote: senocular:
you can also use in
if ("methodname" in object) object.methodname();
Maybe things were slightly different then (I can't recall) but I found that both ways bear some problems. If you use senocular's suggestion, and you dealing with a private method, you are out of luck. Lets say the method onCompleteHandler() exists in a Class x and it's public:
Code:
trace("onCompleteHandler" in this); => TRUE
trace(this["onCompleteHandler"] != null); => TRUE
Now lets make the onCompleteHandler private!
Code:
trace("onCompleteHandler" in this); => FALSE
trace(this["onCompleteHandler"] != null); => TRUE
By removing the method:
Code:
trace("onCompleteHandler" in this); => FALSE
trace(this["onCompleteHandler"] != null); => throws an Error
What worked for me was exactly what deadlock32 couldn't belive he wrote it !!
Code:
var methodExist:Boolean;
try {
methodExist = this["onCompleteHandler"] !=null;
} catch (e:Error) {
methodExist = false;
} finally {
}
Ergo: deadlock32.s "( can't believe i wrote the code below)" wasn't that bad after all. Its the only foolproof solution as far as can see.
Rainer