2.08.2009

Monkeypatching the cached Flex framework RSL

I believe I discovered a *consistent* method to monkeypatch the Flex framework with RSLs. I assume you understand what a preloader is, and how to monkeypatch without RSLs -- there is plenty of documentation on both.

Like the first time you type sudo:
We trust you have received the usual lecture from the local former Flex SDK dev. It usually boils down to these three things:
#1) Respect the privacy of other classes.
#2) Think before you patch.
#3) With great power comes great responsibility.
Create an empty preloader class (or add to an existing one) which contains the following, substituting for whatever you're patching.
    import mx.managers.FocusManager; FocusManager;
And that'll do it. The class will get preloaded, before the cached framework gets loaded. Simple and obvious now, eh?

---
Note: If using RSLs, you may see significant code bloat. Classes get loaded in order of dependency -- if the dependency of UIComponent isn't present when it tries to load, it fails.

So if you are patching high up in the dependency tree, like UIComponent, all the required classes will get compiled into the main SWF, as they are loaded before the RSLs.

Notably, this is unlike how Java's class loader works.