2 Replies Latest reply on Nov 6, 2007 2:32 PM by Anton_Katernoga

    binding handler gets called twice

    Anton_Katernoga
      Hi, I'm new to Flex, so probably I'm doing this wrong.
      I have a form item - checkbox, and a custom class property bound to it.
      <mx:FormItem id="comItem">
      <mx:CheckBox label="Allow Comments" id="comments"
      selected="true"/>
      <mx:CheckBox label="Tree Comments" id="treeComments"/>
      </mx:FormItem>
      I have set up a Change watcher to pass the bound object when the checkbox value is changed.
      ChangeWatcher.watch(comments,"selected",onBinding);
      but my handler gets called twice, once when the event is a FlexEvent, second when it's a MouseEvent..
      I suppose It should get called only once.
      Can you help me?
      Thanks!
        • 1. Re: binding handler gets called twice
          ntsiii Level 3
          ChangeWatcher is an advanced method. Why not simply declare the handler on the tag?

          <mx:CheckBox ..." id="comments" selected="true" change="onBinding(event)"/>

          Tracy
          • 2. Re: binding handler gets called twice
            Anton_Katernoga Level 1
            It doesn't work. The change event occurs before the binding, so in the handler the bound object's property is not set.
            I'll try to describe the task.
            I have a form with options and below it a preview, which should reflect the changes in options immediately, so the user could see what it wold look like with this set of options.
            The preview is a custom comp, and i send it events with the options data (Value object) so that it could update accordingly.

            The only solution I could come up with was to bind the form data to this Config object, and then to dispatch the event with this Config data. I tried first the change handler, but at the moment the handler is called, the binding didn't occur.
            I tried to listen to propertyChange event (binding default trigger) but it didn't work for some reason.
            Then I came to the solution I describe now.
            If anyone knows a better solution on how to do what I want, i can use it. But so far the watcher thing works, but the handler is called twice...