I’ve been intrigued about the Flex framework called MATE ever since I stumbled across it, some months ago. The guys at asfusion.com have always been expert Flex / ActionScript developers and the MATE framework they’ve developed is no exception.
I decided to use MATE rather than Cairngorm in a personal project I’m working on, to check it out in a real world environment (there’s nothing like going beyond examples and prototypes to determine if a framework actually works beyond design patterns and theory).
So far, I’m very impressed.
It’s light weight, easy to integrate, and has a tag to suit almost any situation and many common design patterns. Within half an hour, I had MATE integrated into my project, dispatching events and updating the model.
I did however come across an interesting problem which had me stumped for a while. I’m working on an AIR application in which I have a preferences window (via a NativeWindow popup) which creates, stores and modifies preferences for the application (yes, I’m using as3preferenceslib).
The basic idea behind MATE is to dispatch events and respond to those with changes to the Model using dependency injection to keep your views notified of the changes. All of this happens via a tag called EventMap (MATE is a tag-based framework) which is used to respond to events, change the model and inject changes to data into views. Basically, you whack the EventMap tag into your Application.mxml, use the standard dispatchEvent and magically, everything works.
Unless you’re view is used in a popup window and you want to use MATE events and the model.
The reason being popup windows within AIR have an entirely different displayList to the Application displayList and your EventMap won’t be able to intercept events dispatched using the standard disptachEvent.
After some poking around in the MATE documentation (which is very good by the way) I found a Dispatch tag, which can also be instantiated via ActionScript. So, I simply made an instance of Dispatch and used the dispatchEvent method and once again, magically, everything worked.
var countdownEvent : CountdownEvent = new CountdownEvent(CountdownEvent.SET); countdownEvent.countdown = event.newValue; var d : Dispatcher = new Dispatcher(); d.dispatchEvent(countdownEvent);
Filed under: air, flash platform, flex, frameworks , air, events, mate
Cheers for that mate.
This kinda sounds a bit like iResponder in Cairngorm – but most likely a lot simpler – do you know how they compare?
Matt
Matty V! It’s kinda like iResponder, but not really
Cairngorm uses a Singleton-based Model so you can basically ‘get to Cairngorm’ from anywhere in your views (even if they are in a popup). MATE uses the EventMap to route calls to events; its a tag which you shove into your Application display list.
Within the EventMap you respond to each event that then updates the model (called Managers in MATE). You then use Injectors to provide data updates to views where necessary.
I’ve used Cairngorm in dozens of projects, but I’ve only just started using MATE so I’m probably not in a good position to compare the two. So far is seems really light weight and flexible. For example, you can easily have mutliple EventMaps and Managers (think Models). As you know, the Cairngorm ModelLocator can get pretty polluted through the development life cycle of a large application. Using multiple Managers within MATE is a built-in and elegant to solution to this.
It has many other nice features and tags too and A LOT less wiring involved to get events, business and commands all hanging together, but I suppose the biggest thing I’m getting my head around is that its tag based (I’m used to things being more ActionScript oriented). It’s definitely worth a look though.