3 Replies Latest reply on Sep 30, 2014 3:33 PM by Flex harUI

    FX:Binding   When is it reliable?


      I have always used fx:Binding for datagrids and Value Objects. 


      fx:Binding source="dg.selectedItem as DTO" destination="dto"


      At first, I used it religiously but then when I was debugging my program, I was finding times when it should have had a value but it did not and yet I could use the dg.selectedItem function and it did have the correct value.   Evidently, the cause of this has something to do with processes being asynchronous.   And so I am finding myself using dg.selectedItem more now and not using the variable created using the fx:Binding especially in critical areas such as persisting data.  What I am asking is for someone who knows this topic really well who can explain to me when using the fx:Binding is reliable vs when its not.

        • 1. Re: FX:Binding   When is it reliable?
          Flex harUI Adobe Employee

          Under the covers, binding is pretty simple.  It attaches listeners to things and when a change event is dispatched, it updates itself.  I suppose in some complex network of bindings, a change can take a while to propagate over but it should all settle out before the next screen update.  Now if some asynchronous thing is constantly making changes, I suppose you can see it get out of sync.


          The biggest issue with binding is that folks try to bind to things that don't send change events, like plain objects and arrays, and even XML if the compiler thinks the XML object is just a plain object.  Warnings are usually output by the binding subsystem when you do that, but folks often ignore those and then wonder why things don't work as expected.  In nested object and array data structures, it is often hard to bind to something deep in that structure.  The binding may only update when the entire data set is changed or the entire sub-object instance is replaced, but not when a property is updated.



          • 2. Re: FX:Binding   When is it reliable?
            Michelle5002 Level 1

            So I guess there is no great answer.   Interesting about the Array thing.  Especially since binding arrays is what is taught in Flex in a week training.   Unless an ArrayCollection is different.   Also, when I am sending a change event to a parent class using fx:Metadata and passing out some data.   I think your saying its better to pass out an object and then get its id in the parent than to just pass out the int id itself.    I have been looking at binding as more like pointers and your passing references to memory locations.   Which is why I was surprised to see times when the data was out of sync.   Thanks for the explanation of it being more an event than a pointer.

            • 3. Re: FX:Binding   When is it reliable?
              Flex harUI Adobe Employee

              An ArrayCollection is different.  It wraps an Array and makes it mostly bindable.  What isn't always bindable are changes to sub objects of the objects in an ArrayCollection.  It matters if the object's list of children is an Array vs ArrayCollection, and even then you may have to propagate change events upward.


              IMO, Flex apps should be event driven.  Instead of passing objects or ids, consider dispatching an event and having the event listener get what it needs.