Search code examples
actionscript-3apache-flexflex4

Bindable setter not called if value of property not changed?


(This may be too localized an issue but I will try to generalize it)

Question: If a property setteris marked as Bindable, will it not get called if the new value is the same as the old value?

I am seeing the above behavior in a legacy project I have inherited: the setter is not getting called. If I don't declare the setter as Bindable then the setter is called no matter what the new value is.

Can anyone confirm that the above is the way things are designed to work with Binding?

This project uses Binding all over the place and there are no comments in the code so it is hard to tell what the dependencies are and which parts of the code depend on particular bindings. I'm trying to avoid making major changes but I also don't want to waste time trying to work around something which should be refactored.

The property is bound:

    [Bindable]
    protected var _source:AolMediaFile;

The setter is bound:

    [Bindable]
    public function set source(file:AolMediaFile):void{
          _source = file;
         // do some stuff with file
    }

Solution

  • So digging around here a bit more I came across this question: Flex: Help me understand data Binding on getters and setters which describes the code generated by declaring a setter or getter Bindable

    So apparently in the generated code there is a check to see if the value is different:

    public function set name(value:String)
    {
        if (_name == value)
            return;
        _name = value;
        dispatchEvent(new Event("nameChanged"));
    }