Scott Mebberson

Icon

Web Technologist

MATE: Using the PropertySetter tag

I’ve never understood why many MATE developers don’t use proper getter/setter properties within Managers. I’ve just assumed it is because MethodInvoker is the preferred means to communicate with Managers. Setting an individual property on a Manager hasn’t been an easy thing to do, until now, so I wonder if that will change?

Having read through similar discussions on the forums however, I’m not convinced MATE purists will like/agree with this post, but I feel most confortable with property getter/setter properties and it has always been a common method in ActionScript.

Mate 0.8.6 included a new tag called PropertySetter and my eyes lit-up as soon as I read it on the change log. The PropertySetter tag (there’s no documentation for this tag yet) allows you to communicate with Managers by directly assigning values to a property, and using getter/setter property functions to check, manipulate and fire off other events as necessary.

Before the PropertySetter tag my EventMap used to communicate with Managers like this:

<EventHandlers type="{PreferencesEvent.BREAK_LENGTH}" debug="false">
<MethodInvoker generator="{ApplicationManager}" method="setBreakLength" arguments="{event.value}" /></pre>
</EventHandlers> 

and the related methods within my Managers used to look like this:

private var _breakLength : int = 0;

[Bindable(event="breakLengthChanged")]
public function get breakLength () : int
{
	return _breakLength;
}

public function setBreakLength (value : int) : void
{
	breakLength = value;
}

notice the use of a proper property getter function, but no proper property setter function – that has always felt so awkward to me. With the PropertySetter tag, I can now set a property in my Manager from my EventMap like this:

<EventHandlers type="{PreferencesEvent.BREAK_LENGTH}" debug="false">
<PropertySetter generator="{ApplicationManager}" targetKey="breakLength" source="{event.value}" /></pre>
</EventHandlers> 

and use proper property getter/setter functions in my Manger like this:

private var _breakLength : int = 0;

[Bindable(event="breakLengthChanged")]
public function get breakLength () : int
{
	return _breakLength;
}

public function set breakLength (value : int) : void
{
	_breakLength = value;
	dispatchEvent(new Event('breakLengthChanged'));
}

I’m not sure what the general community at large thinks? I’ve started a thread over on the mate forums to discuss it, but it would be great to hear other peoples opinions on what should be best practice.

Filed under: ActionScript, flex, frameworks, mate

MATE: Responding to events

Recently, I embarked on a personal project to learn about the Mate Framework, which I’ve started hearing more and more about. We’ve successfully used Cairngorm in dozens of Flex/AIR projects at Enpresiv and I thought it was time to try out Mate (apparently pronounced mah-teh).

I’m glad I did, because it is an awesome framework with much flexibility making it suitable for many different types of projects. One of my favourite things about the framework is how quick and easy it is to integrate. It doesn’t force you to use all Mate concepts either, providing endless options for partial integration into existing projects that might just need a little structure.

One of the issues with Cairngorm that a lot of people have trouble with is easily responding to events/commands within a view (albeit the event that dispatched the event or not). I was happily surprised when I found out this is one of the easiest things to do within Mate, and there are two ways to do it!

Mate advocates the Dependency Injection pattern over the Model Locator pattern which Cairngorm advocates. Dependency Injection is a fantastic concept and truly promotes reusable views as the view needs no knowledge of the framework. Your view doesn’t really need to respond to an event directly, it just receives only the required or updated data it needs.

The second means for views to directly respond to events is using the Listener tag, which simply could not be any easier to work with.

I’ve worked up a basic yet focussed example on two options for repsonding to Mate events within views.

I plan on discussing other Mate features in future posts, but thought this was a great starting point as it’s the source of pain for many Cairngorm developers. Although, Universal Mind have released some extensions which make responding to events/commands within views much easier.

Filed under: cairngorm, flash platform, flex, frameworks, mate

About Me

I'm a web technologist living and working in Adelaide, Australia.

My Tweets

Navigation

My Older Posts

Follow

Get every new post delivered to your Inbox.