Suppose (as an example) that I have a class which I want to log all method calls to.
In PHP this can be accomplished quickly and easily with __call(), or in Python with decorators.
What would be the easiest way to accomplish the same thing in Actionscript 3?
Extend
flash.utils.Proxyand use theflash.utils.flash_proxynamespace. There’s methods similar to__get,__setand methods for delete methods as well. For example, the__callmethod is:so if have a class that extends Proxy, you do:
then callProperty will be called and name will be set to “myMethodThatIsntDefined” and “param” will be in the …rest array.
The link to the asdoc has a simple implementation that should get you going. I typically use the Proxy class for something like an API. For example, back in the day I had a Flickr API wrapper that translated the name of the function call to an API method name in the Flickr API. Something like:
and in the callProperty I’d split on the first word to get the API name “flickr.galleries.get_photos”. The names were different back then I think.