Archive for February, 2010

Monkey Patching ListCollectionView

The last in this monkey patch series is mx.collections.ListCollectionView.
I was going to skip the write up on monkey patching this class but I had already
said I was going to do it and there was one interesting twist along the way. I
chose to demonstrate this class because there was a real world case of it
being monkey patched. I haven’t actually patched the class myself I’m just going
to demonstrate how to make a patch work when using RSLs.

This monkey patch is going to follow the same pattern as the
previous two. First I’m going to create the RSL and then add the RSL into the
configuration.

Create an RSL

As usual I compile the monkey patched files into a library
and create a link report. The link report becomes the basis of my externs file.
The size of the monkey patch RSL without externalizing any classes is 38,260
bytes.

Next I start removing classes from the externs file. First I
remove ListCollectionView itself. ListCollectionView extends flash.utils.Proxy.
Proxy is already externalized in playerglobal.swc so nothing to do. Next remove
the three classes ListCollectionView implements, ICollectionView, IList, and
IMXMLObject. ICollectionView and IList both implement IEventDispatcher.
IEventDispatcher is also in playerglobals.swc so nothing to do. With all these
classes removed from the externs file, recompile the RSL.

Add the RSL to the configuration

Since we are monkey patching the framework RSL, add the
monkey patch RSL to load before the framework RSL.

At this point I thought I was done and ran the application.
But I got a VerifyError on mx.collections.CursorBookmark. I couldn’t see how
ListCollectionView extended or implemented CursorBookmark so I opened the catalog
in framework.swc to double check. Sure enough CursorBookmark was an inheritance
dependency of ListCollectionView. Inheritance dependencies are in the catalog
as type=”i”.

 

        <dep
id=”mx.collections:CursorBookmark” type=”i” />

I didn’t understand why so I searched ListCollectionView for
CursorBookmark. I found a private class that extends CursorBookmark:

class ListCollectionViewBookmark extends
CursorBookmark

and another private class that implements IViewCursor:

class ListCollectionViewCursor extends EventDispatcher
implements IViewCursor

With the mystery solved I removed CursorBookmark and
IViewCursor from the externs file and recompiled. This time the application loaded
without error although the application does not actually use ListCollectionView.
The final size of the monkey patch RSL was 8,047 bytes.

Download Source