Tom
Tom

Reputation: 8127

Possible to add an EventListener to a function for Actionscript 3?

I'm trying to setup something like Aspect Oriented Programming in Actionscript 3, basically the only thing I need to be able to do is something like this:

SomeClass.getMethod("methodName").addEventListener(afterMethodExecuted, function() {
    //run code
});

This way I can run code after (or before) any method in any class has run, allowing numerous new possibilities.

How should I implement this?

Upvotes: 0

Views: 122

Answers (1)

James Fassett
James Fassett

Reputation: 41044

You can write a wrapper on a method. The BindUtils class of the Flex library does just that using the ChangeWatcher. It does so by wrapping a property but in ActionScript a method is just a property.

I suggest reading the code for those methods ($FLEX_ROOT/sdks/4.0.0/frameworks/projects/framework/src/) to get an idea of how you can do the same.

You might also be interested in the FunctionReturnWatcher.

Upvotes: 2

Related Questions