开发者

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

I'm trying to 开发者_JAVA百科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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜