Wednesday, March 10, 2010

Monkey Patching in Flex

I recently attended 360Flex. It was an excellent conference. I thought I knew some Flex, but I was certainly not aware of how much others are doing with Flex, Actionscript and the Flash Platform in general. Very interesting concepts. One of the nice concepts I recently learned while at San Jose was "Monkey-Patching".  Fortunately, I had the chance to practice how to use it after the conference and learned so much about the internals of some Flex components.  Here is what I did.

First, let me explain the obvious. "Monkey-Patching" is the concept where one can extend or modify runtime code (for a further explanation, please refer to wikipedia). In this case, we are leveraging the dynamic nature of the ActionScript so as to learn some of the internal operations that occur in the Flash Platform, particularly as pertaining to our Flex code.

As I've been working on Module loading using the ModuleManager class, I decided to try to "Monkey-Patch" the found in the mx.modules folder. I quickly learned more than I knew about the code.  I decided to add trace() calls before each method. Then my code revealed a lot nice goodies about the Module loading mechanism provided. I won't deprive you from the thrill of looking for these, but enough to say that there's some caching (internal) that happens should you try to load the same module twice.  Needless to say, I was very excited to see what else can I do with this.

Among other things worth mentioning (where I heard the term  "Monkey-Patch"), I learned about this project Reflex. It's a framework that it's all about using the Flash Platform (not flex). It's an action-script framework that is meant to reduce the overhead generated (or introduced) with Flex and make component lightweight, thus making faster downloads of SWF files, possibly reducing power energy (so essential in this mobile revolution), etc. The possibilities are endless. I'm very excited to see where this project goes and will try to watch it.

No comments: