Archive for June, 2009

PureMVC: Creating a short-hand Mediator

99% of coding I do lately is built on top of the excellent PureMVC framework. Something that has been irking me for a while now is the way Mediators register and handle notifications dispatched from the View.

Part of working with PureMVC requires extending from the Mediator base class (more specifically implementing IMediator) as this contains two important methods, listNotificationInterests and handleNotification. Where this starts to get a little painful is you need to override both of those methods for every Mediator you create. That is where I came up with the idea of abstracting away these two methods by creating a ‘helper method’ which will map a notification to a handler. I should say that before doing this I searched on the PureMVC forums and found several people who have already encountered this issue and created their own implementations.

I’ve created my own extended version of the base Mediator class I’ve called AbstractMediator. This includes a custom method called registerNotificationHandler which you pass a notification name and call back method to. This is very similar to the addEventListener method used in AS3. Then you simply extend AbstractMediator instead of Mediator in your application. AbstractMediator automatically populates the array returned by listNotificationInterests and uses handleNotification to route incoming notifications to the mapped functions, thus you no longer need to explicitly override these.

Overall the main reason I wanted to create this was to significantly shorten the amount of code needed in each Mediator. *Cliff Hall, creator of PureMVC, has commented on this post below noting that once you account for separate functions to handle notifications it is not necessarily shorter than the default way of overriding listNotificationInterests and handleNotification.

Download.

SWFObject 2.2 Out Now!

Just got word that SWFObject 2.2 is now out and available for download.

SWFObject is THE way to embedd Flash content in HTML and is a MUST have for any Flash user. What’s great about SWFObject is it’s ability to degrade gracefully across various browsers by either throwing up a Flash express install dialog or alternate non-flash content.

Check out the What’s New page over at Google Code to see the latest features and changes.