The World’s Smallest Tag?

If you are developing an MVC application with Flex, sooner or later you are going to want to trigger some functionality in your view when a property in your model changes. A common approach for achieving this is to use a binding tag in conjunction with a property setter in your view component. You bind your view’s property setter to the relevant model property and put your view logic in the setter function. Every time the property changes, your view logic executes.

I have never been particularly satisfied with this approach because it requires me to add a ‘fake’ property to my view component. So I created the Observe tag as a possible alternative, and I think it may also qualify as the world’s smallest tag:

public class Observe
public var handler : Function;

public function set source( source : * ) : void

You use the tag as follows:

<util:Observe source="{ model.myProperty }"
handler="{ this.myFunction }"/>

Because this is such a large and complex component, I need to call on the ever-resourceful Flex community to test it. So feel free to use it in your applications if you want to, and please let me know if you find any bugs.

Update: Please check Alex Uhlmann’s blog for a more recent update of the Observe tag.