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.
Did you put a trace in the setter to make sure it isn't called?
Is periodChangeAmount
a Bindable
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.
private var privateVar:Boolean = false;
[Bindable]
public function set readWriteProp(value:Boolean):void
{
trace("set called with " + value + " current is " + privateVar);
privateVar = value;
}
public function get readWriteProp():Boolean
{
trace("get called : " + privateVar);
return privateVar;
}
//...
a.readWriteProp = true;
a.readWriteProp = true;
Traced output:
get called : false
set called with true current is false
get called : true
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With