6 Replies Latest reply on Aug 14, 2007 11:33 AM by marrrrrrrc

    HTTPService request for each View inside a ViewStack

    marrrrrrrc
      Can someone point me in the right direction to have a httpservice request for each view inside my viewstack?

      <mx:ViewStack id="views">
      <mx:Canvas id="view0">
      .......
      </mx:Canvas>
      <mx:Canvas id="view1">
      ..............
      </mx:Canvas>
      </mx:ViewStack>

      Can someone whip together a quick example or just point me in the right direction?

      Thanks
        • 1. Re: HTTPService request for each View inside a ViewStack
          ntsiii Level 3
          Ahh, don't do that.

          Use a central HTTPService instance, and use AsyncToken to keep track of which result goes where. Some code snippets below.
          Tracy

          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) {
          case "myQuery1":
          doQuery2();
          break;
          ...
          }
          }//onResult
          • 2. Re: HTTPService request for each View inside a ViewStack
            ntsiii Level 3
            Further suggestion: build your app with its data models (XML in instance variable, for example) at the main app level. Hard-code some sample data for development.

            Use binding in the Views to get the data from the central models.

            If your Views are more than a few lines long, implement them as components. Pass the data model into the component using a setter method.

            Tracy
            • 3. Re: HTTPService request for each View inside a ViewStack
              ntsiii Level 3
              When you update the main data model variable, binding will automatically update your components.

              Do not attempt to set the data into the components from the parent. Viewstack uses deferred instantiation, so use binding.

              Tracy
              • 4. Re: HTTPService request for each View inside a ViewStack
                marrrrrrrc Level 1
                I sort of get what you are saying. I just started with flex two weeks ago so I'm a newb.

                I'm seeing about porting over a php/ajax dashboard so I'm going to be calling data from multiple sources/servers. Thats why I was wondering if it was possible to use httpservice multiple times. I got mockups done for all of the views so I know what I need to do is possible (with the charting and yahoo maps.) Also the data I'm going to be pulling for each of these views is completely different.

                I'm going to look into amfphp since the backend is all php already.
                • 5. Re: HTTPService request for each View inside a ViewStack
                  ntsiii Level 3
                  Ok, c'mon back if you decide to use HTTPService.
                  Tracy
                  • 6. HTTPService request for each View inside a ViewStack
                    marrrrrrrc Level 1
                    This is what I ended up doing:

                    I created each view inside the viewstack as a component. Then created a httpservice for each component. I set it to load the httpservice when the view is initialized.

                    It works great now.