Okay, I've been banging my head against the wall with this one. I have the following set function in Flex.
public function set periodChangeAmount(value:int):void
{
_PeriodChangeAmount = value;
refreshStartEndDates();
}
If I set the periodChangeAmount to -1 or 1 the set method gets fired. If I set it to zero it doesn't get fired. What's the deal? Does anyone know why it wouldn't get called when setting it to zero. If I change the object type to a number or even an object it still doesn't work as expected. Any help would be greatly appreciated.
Best Answer
Did you put a trace in the setter to make sure it isn't called?
Is
periodChangeAmount
aBindable
read-write property? In that case flex internally calls the getter to make sure that the value to be set is not the existing value. If the current value of the property (as returned by the getter) is same as the value to be set, the setter is not called.Traced output:
Note that the getter was called twice but the setter was called only once. In the second assignment, since the current value and value to be set are same (true), the setter is not called.
I believe flex dev team did it this way to avoid redundancy in binding.