1 Reply Latest reply on Dec 28, 2007 6:52 AM by paulfeuer

    Aggregating multiple bindable data sources into one

    revmischa
      My problem is that I have an HTTPRequest object that gets its parameters from a couple different sources. I have two bindable objects that contain different sets of parameters to use, but I can't seem to create a bindable model that combines the two objects. I don't want to have to manually resend the request when one of the sources of parts of the bindable objects changes, I want to use the awesome binding capabilities built-in!

      Basically I have object1 = {"foo": "bar"} and object2 = {"lol": "dongs"} and I want my HTTPRequest to use {"foo": "bar", "lol": "dongs"} as the params and be bound to both objects. Is this possible? I basically want something like:
      <mx:Model id="wtf">
      <data>
      {object1}
      {object2}
      </data>
      </mx:Model>

      Any ideas how to accomplish this?
      Thanks
        • 1. Re: Aggregating multiple bindable data sources into one
          paulfeuer Level 1
          i would create a little class that has your HTTPRequest as a member, and allows the other part of your app to register the objects. then, if they're simple dynamic Objects like you have there, i would try to figure out how to use BindingUtils to "watch" the properties of the registered objects - this will give you a chance to register your own change handlers. your change handler will compose the new url params and invoke the service.

          note that you may want to separate the handling of changes with the invocation of the service so that if two properties change back-to-back, you don't call the service twice.

          you can separate them by accumulating the changes, and when change happens, capture the "version" and fire up a timer to send off the update after 200ms if it's still the same version.

          var version:int = 0;
          private function onChange( evt:Event ):void
          {
          var v:int = ++version;
          var timer:Timer = new Timer( 200, 1 );
          timer.addEventListener( Timer.TIMER_COMPLETE,
          function(evt:TimerEvent ):void {
          sendChanges(v);
          });
          timer.start();
          }
          private function sendChanges( v:int ):void
          {
          if( v != version ) return; // there must have been an update afterwards
          // build params here
          // call service here
          }


          ./paul