5 Replies Latest reply on Jul 30, 2007 10:47 AM by edaniel1984

    how to read from a binded ArrayCollections

    edaniel1984
      hello - i have a question regarding data binding.

      my app has 2 sets of combo boxes - and an update button (calls update( ) ) - when the update button is pushed WP1.Ops.send(a1,a2) and WP2.Ops.send(b1,b2) is send.

      then - i have a columnChart with 2 series - with two different dataproviders where they are both binded to either WP1.Ops.lastResult and WP2.Ops.lastResult.

      now comes the tricky part - i need the columnChart's dataprovide to be the union of both series so i can show all the data.

      thus when calling the update( ) - after the send commands , WP1.Ops.lastResult and WP2.Ops.lastResult. comes up to be null - any ideas how to get those values using action script?

      please help.






        • 1. Re: how to read from a binded ArrayCollections
          ntsiii Level 3
          No magic. You will just have to iterate over the ArrayCollections and combine the data manually.

          Tracy
          • 2. Re: how to read from a binded ArrayCollections
            ntsiii Level 3
            Do not bind to lastResult. Use a result handler function. In that you can access the returned data.

            Tracy
            • 3. Re: how to read from a binded ArrayCollections
              edaniel1984 Level 1
              how do i access the data through that function ? (send in an event? if so what kind of event)
              • 4. Re: how to read from a binded ArrayCollections
                ntsiii Level 3
                All the RPC data services provide "result" and "fault" events. the below is for HTTPService but WebService and Re3moteObject are similar.

                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
                • 5. Re: how to read from a binded ArrayCollections
                  edaniel1984 Level 1
                  thanks for the solution -
                  i think i found another way - instead of convert the objects to XML ... convert the objects to Array Collection instead ...

                  private function OnListEnvironment(event:ResultEvent):void
                  {
                  var tempSeries:ArrayCollection;
                  tempSeries = new ArrayCollection();
                  tempSeries = event.result as ArrayCollection;

                  //do manipulation
                  tempSeries.addItemAt("Select Environment ",0);
                  .....

                  finalList= tempSeries;
                  }

                  then make sure that the finalList is the dataProvider.