2 Replies Latest reply on Aug 10, 2006 6:25 PM by WHawke

    Is this pleasant surprise with mx:Binding by Design?

    WHawke
      I was afraid the following scenario would cause an infite loop but decided to "try it anyway". What I was expecting didn't happen....it actually appears to work and I'm pleasantly surprised. Is this by design and is this okay to do? (I'm guessing this is a result of the 'bindable property chain'?)

      Background:
      I have a form that pulls initial data down from a web service method to populate user controls.
      The user edits that data and sends the changes back using an alternate web service method.

      Desired:
      Minimum coding, typeing, etc...just an all around 'lazy way' of doing it ;-)
      Read the intial into the data model and populate the user interface. Changes from the
      user interface update the underlying data model AND changes to the data model are
      updated in the user interface.

      Solution:
      Below is the code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      <mx:Script>
      <![CDATA[

      import mx.controls.Alert;

      private function SimulateGetWebService():void
      {
      CustomerModel.Name = "John Smith";
      CustomerModel.State = "Tennessee";
      }

      public function SimulateSendWebService():void
      {
      Alert.show(CustomerModel.Name, "CustomerModel Data");
      }

      ]]>
      </mx:Script>

      <mx:Model id="CustomerModel">
      <Customer>
      <Name></Name>
      <State></State>
      </Customer>
      </mx:Model>

      <!-- UI to Data Model -->
      <mx:Binding source="TextBoxName.text" destination="CustomerModel.Name"/>
      <mx:Binding source="TextBoxState.text" destination="CustomerModel.State"/>

      <!-- Data Model To UI -->
      <mx:Binding source="CustomerModel.Name" destination="TextBoxName.text"/>
      <mx:Binding source="CustomerModel.State" destination="TextBoxState.text"/>

      <mx:Label x="10" y="10" text="Name"/>
      <mx:Label x="12" y="40" text="State"/>
      <mx:TextInput x="55" y="8" id="TextBoxName"/>
      <mx:TextInput x="54" y="38" id="TextBoxState"/>

      <mx:Button x="160" y="68" label="Send" click="SimulateSendWebService();"/>
      <mx:Button x="106" y="68" label="Get" click="SimulateGetWebService();"/>

      </mx:Application>


        • 1. Re: Is this pleasant surprise with mx:Binding by Design?
          ntsiii Level 3
          Yes it is by design and is how you set up two-way binding.

          Believe it or not some folks have complained that this should be easier!

          Tracy
          • 2. Re: Is this pleasant surprise with mx:Binding by Design?
            WHawke Level 1
            Tracy,

            quote:

            Yes it is by design and is how you set up two-way binding.

            Thanks for the encouraging response. I was afraid I had stumbled onto an unsupported side affect (lol). After adding my real webservices to the mix, it's really difficult to just call it two-way databinding (more like intelligent mult-cast databinding :-) )

            quote:

            Believe it or not some folks have complained that this should be easier!

            I'd be curious to find out what they propose would be easier. Maybe some kind of graphical designer to create mx:Binding links?

            Thanks again,
            Daniel