Checking anonymous function signatures at runtime (reflection) in AS3

Is there any way to have a look at signatures of anonymous functions in ActionScript 3 during runtime?

I would like to validate Function objects passed in as arguments to other functions and make sure that they accept the correct number of arguments (with the correct types) and return a value of the correct type.

flash.utils.describeType() doesn't seem to return this info for anonymous functions.


It doesn't look like the runtime allows you to reflect on anonymous functions, which is a shame.

Anonymous functions are (perhaps by definition) marked as dynamic. If you pass an incompatible type into an anonymous function, no error is thrown. Any type mismatches will be silently cast as best they can. Passing something like "minotaur" as a uint parameter will yield 0 (zero), for example.

If you REALLY want to over-engineer it, you could get all OO on it. Instead of accepting anonymous functions, you could declare an interface which contains the appropriate function signature, and accept objects that implement that interface.

public interface IFancyCallback {
  public function fancyFunction(frog:Frog, princess:Girl):UsefulReturnType;

And your function would just have to be packaged up in an object:

public class ConcreteCallback implements IFancyCallback {
  public function fancyFunction(frog:Frog, princess:Girl):UsefulReturnType {
    return new UsefulReturnType("jabberwocky");

Could have the potential to create a lot of code overhead. Depends how many callbacks you intend to have, who's going to be making them, and what how serious it would be if the anon function's signature was incorrect.

Can you share any more about the problem you're trying to solve?

Need Your Help

How to expose a service layer to UI components

c# .net wcf appfabric

We have an application in which we have created a service layer with most of the business logic and utility services (logging, exceptions, caching etc). We have to come with a way to expose this se...