开发者

Weird behavior in BindingUtils.bindProperty: non deterministic

I'm going slightly mad.

I'm having weird pr开发者_开发百科oblems with BindingUtils.bindSetter and bindProperty. I thought that, if I'd bind two variables with BindingUtils.bindProperty I could be sure they would always be synchronized. But it's not so.

I have this code in a creationCompleteHandler:

BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);

But when I debug, the two variables that should be bound together at some point have different values:

Weird behavior in BindingUtils.bindProperty: non deterministic

What am I missing?

Thanks in advance, Nuno


The binding you defined is one-way. When drhHold.pending is set, then this.pendingHold will get set. This does not go the other way around.

In other words, what you are describing can happen if you have the following code:

this.drhHold.pending = false;
this.pendingHold = true;

If you want this to go both ways, then you need to set up the other direction:

BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);
BindingUtils.bindProperty(drhHold, "pending", this, "pendingHold", false, true);

All of this, of course, assumes that both of these properties are [Bindable].


Binding isn't needed in this case:

public class Class1
{
   private var _class2:Class2 = new Class2();

   [Bindable]
   public function get pending():Boolean
   {
      return this._class2.pending;
   }

   public function set pending(value:Boolean):void
   {
      this._class2.pending = value;
   }
}

As long as Class2.pending is bindable as well, this will make it so that Class1.pending is binded to Class2.pending.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜