Using Bindable variables and properties in Flex (Action Script 3) is great, it saves a huge amount of time adding events left right and center. However today I had a problem where I wanted to use a setter for a variable. In order to do this I made it private and used a getter and setter function, allowing me to add some logic when setting the variable.
The problem however is that private variables are unbindable. You will get a warning on anything bound to it, saying it will not see changes. There is a very simple way to get around this, but making the getters and setters bindable.
[Bindable]
public function set yourVar ( s : String ):void
{
//Some logic can go here
_yourVar = s;
}
public function get yourVar ( ):String
{
// Some logic perhaps
return _yourVar;
}
By putting the [Bindable] tag before the function (I assume you only need it above one), any variables bound to yourVar will work. You don't need a [Bindable] before your declaration of the private _yourVar and you should use yourClassInstance.yourVar when binding, rather than _yourVar.
Hope that helps someone.