The Flex databinding system is a relatively simple yet powerful mechansim for moving data throughout your application. However, there are times when binding will appear not work, and I’d like to give some suggestions on tracking that down.
- Don’t ignore warnings! It’s easy to see a warning and think that it doesn’t matter, especially if binding appears to work at startup. Warnings actually mean something! If the warning is about a missing
[ChangeEvent]on a getter/setter it means that even if the binding works at startup, subsequent changes to the property will not be noticed. If the warning is about a static variable or built-in property, changes will not be noticed. Finally, if you’re sure that the property should be bindable but the compiler is complaining about an unknown type, you may need to cast an object in your binding expression so the compiler can find the appropriate type information (including
[ChangeEvent]metadata). The Flex docs should discuss this in more detail.
- Make sure that the source of the binding did actually change. This seems obvious, but it’s easy for your source to be part of a larger procedure and to miss the fact that it was never assigned.
- Make sure that the ChangeEvent is being dispatched. You can use fdb or another debugger to make sure that your
dispatchEventcall is happening. Also, you can add a normal event listener to that class and make sure it gets called (if you want to add the event listener as a tag attribute you’ll need the
[Event('myEvent')]metadata at the the top of your class definition or in the
<mx:Metadata/>section of your MXML).
- 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 makes sure that the binding itself is working. If the setter is called with the right information, you now know that it’s your destination that is failing and you can start debugging in there.
If you’ve tried the above and things still aren’t working it might be time to get some code on flexcoders or the support forums (support forums are obviously more official but as of this writing flexcoders is pretty responsive). If at all possible bring your problem down to one or two files (this may mean creating a separate simulation just for discussion) so that you don’t need to share your whole source and we can work with just the problem. If you can’t send a simple subset the next thing is at least the files that are causing problems along with the -generated.as debugging file (which you can get by setting
<keep-generated-as>true</keep-generated-as> in flex-config.xml.
If you have any questions on the binding system that aren’t discussed in the docs feel free to ask them here.