Setter Functions in Flex
Tuesday May 29, 2007
Despite my constant entreaties to the compiler, I ran into a wall of behavioural problems in some code which ceaselessly eff’d me off no end. A few rounds with the debugger at first heralded no results, leaving me more bemused than a shrew at a disco.
A while later when I returned, the problem was clearer than freshly cleaned French windows, so I thought I’d share the perspicuity.
It amounts to this – if you have program logic in a setter, and you set a value to a value that is no change from the previous, then your setter logic won’t fire.
For example
public function get someVar() : int { ... } public function set someVar(value:int) : void { // Some setter logic if (value == 2) {someMethod(); }}Some method will not fire twice if you consecutively set someVar to 2.
If you have setter logic that you always want to fire, use the bindSetter() method in the mx.binding.utils.BindingUtils class.