2 Replies Latest reply on Nov 3, 2008 11:53 AM by Yaron_Gilboa

    A problem with binding a visual control to a class property defined with a getter&setter pair


      I am having the following problem (simplified here for clarity):

      I am using a class for data model with a property named x (using a getter & setter) as follows:


      public class MyData
      private var _x :String;

      public function MyData()
      _x = "default value";

      public function set x(value:String):void {
      trace("setting x with: '" + value + "'");
      _x = String(value);

      public function get x():String {
      trace("getting x: '"+_x+"'");
      return _x;

      I then linked (binded) the x property to a TextInput, as follows:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      private var _data:MyData = new MyData();

      <mx:TextInput id="inputX" text="{_data.x}" />

      When loaded, inputX is set with the "default value". However, when changing the value of inputX the value of _data.x remains unchanged (in this sample - there are no trace messages from the setter).

      I have tried numerous variations using <mx:Bindind ...>, mx.bindinding.utils.BindingUtils, changing order of setter and getter, and more.

      The only solution i could find for now is to add a change event handler to the inputX control as follows:

      <mx:TextInput id="inputX" text="{_data.x}" change="_data.x=inputX.text"/>

      Is there something i did wrong? or is it ... simply ... a bug ?