Data binding in Flex is a great tool for automatically linking the data in your model to your view.

However when you want to define your own bindable data sources through the use of getters and setters, the bindings don’t seem to work.

So what’s the solution?

The trick is to first define a bindable event for your getter:


You then need to dispatch this event whenever the property changes within your setter:

dispatchEvent (new Event ("propertyChange"));

That’s all there is to it!

Whenever your property changes (via the setter method), an event is dispatched that notifies any components linking to the property (via the getter method) that the property has been updated.

Here’s some example code you can enjoy with a glass of awesome:

Update: Code snippets I’ve posted using Private Paste are randomly disappearing, so if the above link no longer exists, here’s a backup.