Revisiting the Flex whiteBox issue in Flex 3
Posted on May 24, 2008 | Filed Under Adobe Flex
I expected the Container.whiteBox issue (discussed here and here) to be resolved with the release of Flex 3, but readers have pointed out that the issue still exists. With this in mind, I decided to offer another solution to the problem. The technique used in this solution is referred to as Monkey Patching. I first saw the technique described by my fabulously talented UM coworker, Doug McCune.
Basically, the Flex compiler always uses the last provided implementation of a package/class whenever it encounters multiple implementations. This behavior allows us to replace parts of the Flex framework without having to recompile the framework SWC file. Applying a monkey patch is as simple as copying the source files and their parent directory structure into our project source folder and making the desired changes.
Take a look at the source for the example app seen above by right-clicking and selecting the “View Source” option. There is an “mx.core” folder that contains the ContainerRawChildrenList.as and Version.as source files. We’ll be changing the ContainerRawChildrenList.addChild method (beginning on line 141) to set the child’s visible property to false if it is named “whiteBox”. FYI, Version.as is also copied but not modified because it is included by the ContainerRawChildrenList.as file.
The great thing about monkey patching is that the changes are applied application wide. In this case, all Container-derived classes will include the whiteBox fix with no other modifications needed for your application code. There are some caveats though.
First, monkey patching impacts your ability to take advantage of the new Flex 3 framework caching feature. I haven’t tried this myself, but it is my understanding that monkey patching will either make your app ineligible for framework caching or your monkey-patched version will be ignored. My advice in regards to this issue: If you’re creating a simple, small app, add the fix to individual classes as described in my previous posts. If you’re creating a substantial app where the Flex framework comprises a small percentage of the total app filesize, disable framework caching and use this solution.
You will also have to update your monkey-patched files whenever the Flex framework is updated. This doesn’t occur too often presently, but it will be one more issue to add to your application “ongoing maintenance” list.
About this Post
Permalink | Trackback |
|
Print This Article |
Comments
4 Responses to “Revisiting the Flex whiteBox issue in Flex 3”
Leave a Reply

Cul fix. Thanks
Very cute. Also, thanks for the terminology.. I’ve monkey-patched bits of MFC before, but never had a good word for it.
A designer fix could be to wrap the container in a canvas, and overlay the whitebox with a box of the desired color at x = “canvas.width - newColorBox.width” and y = “canvas.height - newColorBox.height”
Coders are cringing, probably. But it’s a quick fix and doesn’t require updating. It could be it’s own component, if the app were really big.
Maybe it’s Monkey Designing.
Hey Jeff, your suggestion could work provided the needed color was a single color (no gradient). I was working with a gradient background when I originally ran into this.
However, you should be aware that the framework code destroys the whiteBox object whenever scroll bars are removed and reinstantiates it again when they are added. You would have to keep up with this and keep your colored box on top of the newly-instantiated whiteBox object.