Adobe Flex 3 Help

Considerations for using the binding feature

Consider the following when using the binding feature:

  • You cannot bind to style properties.
  • If you bind a model into the dataProvider property of a component, you should not change items in the model directly. Instead, change the items through the Collections API. Otherwise, the component to which the model is bound is not redrawn to show the changes to the model. For example, instead of using the following:
    myGrid.getItemAt(itemIndex).myField = 1; 
    
    

    You would use the following:

    myGrid.dataProvider.editField(itemIndex, "myField", 1);
    
    
  • Array elements cannot function as binding sources at run time. Arrays that are bound do not stay updated if individual fields of a source Array change. Binding copies values during instantiation after variables are declared in an <mx:Script> tag, but before event listeners execute.

Debugging data binding

In some situations, data binding may not appear to function correctly, and you may need to debug them. The following list contains suggestions for resolving data binding issues:

  1. Pay attention to warnings.

    It is easy to see a warning and think that it doesn't matter, especially if binding appears to work at startup, but warnings are important.

    If a warning is about a missing [Bindable] on a getter/setter property, even if the binding works at startup, subsequent changes to the property are not noticed.

    If a warning is about a static variable or a built-in property, changes aren't noticed.

  2. Ensure that the source of the binding actually changed.

    When your source is part of a larger procedure, it is easy to miss the fact that you never assigned the source.

  3. Ensure that the bindable event is being dispatched.

    You can use the Flex command-line debugger (fdb), or the Adobe® Flex® Builder™ debugger to make sure that the dispatchEvent() method is called. Also, you can add a normal event listener to that class to make sure it gets called. If you want to add the event listener as a tag attribute, you must place the [Event('myEvent')] metadata at the top of your class definition or in an <mx:Metadata> tag in your MXML.

  4. Create a setter function and use a <mx:Binding> tag to assign into it.

    You can then put a trace or an alert or some other debugging code in the setter with the value that is being assigned. This technique ensures that the binding itself is working. If the setter is called with the right information, you will know that it's your destination that is failing, and you can start debugging there.