2 Replies Latest reply on Nov 1, 2010 11:02 PM by Flex harUI

    Getter setter problem

    SiHoop Level 1

      I'm trying to use a setter for two reasons: to set the value of a variable and to execute a method. However, when I call the setter with a value where the variable does not change, the setter fails to execute.

       

              public function set canvasPosition(value:Number):void{
                  _canvasPosition=value;
                  model.canvasPosition=_canvasPosition;
              }
      Presumably, the variable looks at its value and says to itself: "My value doesn't change, so there's no point in executing the setter"

       

      My solution is to call the setter twice:

                      controller.canvasPosition=1;
                      controller.canvasPosition=0;

       

      This solves the problem, but there has to be a better way! How can I force the setter to execute?

        • 1. Re: Getter setter problem
          Flex harUI Adobe Employee

          If you accidentally set on the set function or the class there

          might be generated code that doesn't call unless the the value has changed.

          Otherwise any change check has to be in your code.

           

          Get/set functions should use [Bindable("someEvent")] and dispatch the event

          themselves.

           

          To prove it, add a trace statement that dumps the old and new value and see

          if it traces out when the value doesn't change.

          • 2. Re: Getter setter problem
            drkstr_1 Level 4

            Hmm, well a setter will do exactly what you tell it to. There is nothing built in that value checks. Do you mean that it's not executing in your model setter? If that's the case, post the code.