Misunderstanding the Basics of Dynamic Data Binding (bindPropety) In Flex

I need to dynamically bind properties of components created at runtime. In this particular case, please suggest that I need to use bindProperty.

I do not quite understand why the following simplified test does not work (see code). When I click the button, the text of the label does not change.

I understand that in this particular example there are simpler ways to use traditional non-dynamic binding, but I need to understand this in terms of using bindProperty.

Can someone please help me understand what I am missing?

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="Tools.*" minWidth="684" minHeight="484" xmlns:ns2="*" creationComplete="Init();">
  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.binding.utils.*;
      public var Available:ArrayCollection=new ArrayCollection();

      public function get Value():String {
        return (Available.getItemAt(0).toString());
      }

      public function Init():void {
        Available.addItemAt('Before', 0);
        BindingUtils.bindProperty(Lab, 'text', this, 'Value');
      }

      public function Test():void {
        Available.setItemAt('After', 0);
      }
    ]]>
  </mx:Script>
  <mx:Label x="142" y="51" id="Lab"/>
  <mx:Button x="142" y="157" label="Button" click="Test();"/>
</mx:WindowedApplication>

Thanks in advance.

+5
source share
2

, [Bindable] Value.

, . . : setter - Flex , getter.

  [Bindable]
  public function get value():String {
    return (Available.getItemAt(0).toString());
  }

  public function set value(v:String):void {
    Available.setItemAt(v, 0);
  }

  public function init():void {
    Available.addItemAt('Before', 0);
    BindingUtils.bindProperty(Lab, 'text', this, 'Value');
  }

  public function iest():void {
    value = "After";
  }

, . InitialCaps .

+3

BindingUtils, , [Bindable] "Value".

+1

All Articles