6 Replies Latest reply on Dec 31, 2008 9:43 PM by VarioPegged

    Handling Result Values in Flex

    priyaram1
      Hi,

      I have a button in my flex application.Inside the click() event of this button, i'm calling a webservice(that returns a string value) four times with four different input values.Each time , i'm capturing the return value and displaying in a different label.But irrespective of the intended return value for each corresponding input value, all the four labels are displaying the same value.Also on the first "CLICK" of the button all the four labels are dispalying Empty String Values.When the button is clicked further all the four labels are displaying the same values and these values are varying each time we run the application.Please suggest a solution for this?

      I have attached the code too....
        • 1. Re: Handling Result Values in Flex
          Level 7

          "priyaram1" <webforumsuser@macromedia.com> wrote in message
          news:gjcg0r$6e2$1@forums.macromedia.com...
          > Hi,
          >
          > I have a button in my flex application.Inside the click() event of this
          > button, i'm calling a webservice(that returns a string value) four times
          > with
          > four different input values.Each time , i'm capturing the return value and
          > displaying in a different label.But irrespective of the intended return
          > value
          > for each corresponding input value, all the four labels are displaying
          > the
          > same value.Also on the first "CLICK" of the button all the four labels are
          > dispalying Empty String Values.When the button is clicked further all the
          > four
          > labels are displaying the same values and these values are varying each
          > time we
          > run the application.Please suggest a solution for this?
          >
          > I have attached the code too....
          >
          > import mx.collections.ArrayCollection;
          > import mx.controls.Alert;
          > import mx.managers.CursorManager;
          > import mx.rpc.events.FaultEvent;
          > import mx.rpc.events.ResultEvent;
          > import mx.rpc.soap.WebService;
          > import mx.utils.StringUtil;
          >
          >
          >
          > include "mainConfig.as";
          >
          > private var gateway:WebService = new WebService();
          >
          > [Bindable]
          > public var strDateHigh:String;
          >
          > private function initApp():void
          > {
          > gateway.wsdl = ENDPOINT_URL;
          > gateway.loadWSDL();
          > gateway.GetDateDiff.addEventListener(ResultEvent.RESULT,
          > fillHandlerDateDiff);
          >
          >
          >
          > }
          >
          > private function fillHandlerDateDiff(e:ResultEvent):void
          > {
          > strDateHigh=String(e.result);
          > }
          >
          > private function CheckValues():void
          > {
          >
          > gateway.GetDateDiff("High");
          > l1.text=strDateHigh;
          >
          > gateway.GetDateDiff("Low");
          > l2.text=strDateHigh;
          >
          > gateway.GetDateDiff("Medium");
          > l3.text=strDateHigh;
          >
          > gateway.GetDateDiff("Significantly");
          > l4.text=strDateHigh;
          >
          >
          > }

          Several things are working against you here.

          The first is that you can't pile up calls on the same RemoteObject like
          this. You need to wait for the first to come back before you call the
          second, etc., or the subsequent calls will never happen.

          The second is that you seem to be assuming that you can make a call and then
          somehow immediately the result handler will fire and set a string which you
          can then use on the line after you call the service. That's not how it
          works. The result handler will fire when the result comes in--and there is
          no way its value will _ever_ be available in the line right after the
          service gets called.

          Try something like this:

          private var labelToFill:Label;

          private function checkValues() {
          switch (labelToFill) {
          case null:
          labelToFill = l1;
          gateway.GetDateDiff("High");
          break;
          case l1:
          labelToFill = l2;
          gateway.GetDateDiff("Low");
          break;
          case l2:
          labelToFill = l3;
          gateway.GetDateDiff("Medium");
          break;
          case l3:
          labelToFill = l4;
          gateway.GetDateDiff("Significantly");
          break;
          default:
          //reset so it will work next time
          labelToFill=null;
          }
          }

          private function fillHandlerDateDiff(e:ResultEvent):void
          {
          labelToFill.text = String(e.result);
          checkValues();
          }

          Note that you're probably better off just calling the service once and
          returning a typed object with high, low, medium, etc. properties.

          HTH;

          Amy


          • 2. Re: Handling Result Values in Flex
            priyaram1 Level 1
            Thanks a lot...
            But i need some more clarification regarding this..........

            I need this return values for a diffrent purpose rather than just displaying the values in labels.
            In my application,i have a column chart with a single series.Within the single series,i have four coulmns with xValues "High","Low","Medium","Significatly" .These four columns has to be displayed in diffrent colors based on the return values from the webmethod.I need to call this webmethod for each of the Xvalues "High","Low","Medium","Significatly".Each time the return value is to be compared with string values either "Low" or "High". If it is "Low",the corresponding column must be displayed in RED color, or if it is "High", the corresponding column must be displayed in GREEN color.Is it possible to write any chart event to get the output?Or any other alternative?

            • 3. Re: Handling Result Values in Flex
              Level 7

              "priyaram1" <webforumsuser@macromedia.com> wrote in message
              news:gjf0pi$f1q$1@forums.macromedia.com...
              > Thanks a lot...
              > But i need some more clarification regarding this..........
              >
              > I need this return values for a diffrent purpose rather than just
              > displaying
              > the values in labels.
              > In my application,i have a column chart with a single series.Within the
              > single
              > series,i have four coulmns with xValues
              > "High","Low","Medium","Significatly"
              > .These four columns has to be displayed in diffrent colors based on the
              > return
              > values from the webmethod.I need to call this webmethod for each of the
              > Xvalues
              > "High","Low","Medium","Significatly".

              And why is it you think it's more efficient to call it separately than to
              call it once and split it out?

              >Each time the return value is to be
              > compared with string values either "Low" or "High". If it is "Low",the
              > corresponding column must be displayed in RED color, or if it is "High",
              > the
              > corresponding column must be displayed in GREEN color.Is it possible to
              > write
              > any chart event to get the output?Or any other alternative?

              Could you rephrase this? I couldn't make any sense of your words.


              • 4. Handling Result Values in Flex
                VarioPegged Level 2
                A little difficult to follow what you're looking to do, but I'd suggest using AsyncToken to determine which call is being returned. Because the AsyncToken class is dynamic, you can assign custom values to dynamic properties, like token.id, or token.customProperty, or whatever.

                Here's a rudimentary sample.

                TS
                • 5. Re: Handling Result Values in Flex
                  Level 7

                  "VarioPegged" <webforumsuser@macromedia.com> wrote in message
                  news:gjh2pl$6vs$1@forums.macromedia.com...
                  >A little difficult to follow what you're looking to do, but I'd suggest
                  >using
                  > AsyncToken to determine which call is being returned. Because the
                  > AsyncToken
                  > class is dynamic, you can assign custom values to dynamic properties, like
                  > token.id, or token.customProperty, or whatever.
                  >
                  > Here's a rudimentary sample.
                  >
                  > TS
                  >
                  > ...
                  >
                  > private function CheckValues(paramArray:Array):void
                  > {
                  > var arrLen:int = paramArray.length;
                  >
                  > for (var i:int = 1; i <= arrLen; i++)
                  > {
                  > var token:AsyncToken = gateway.GetDateDiff(paramArray );
                  > token.addResponder(new AsyncResponder(onResult, onFault, token));
                  > token.id = i.toString();
                  > }
                  > }
                  >
                  > private function onResult(data:Object, token:Object = null):void
                  > {
                  > this["l" + token.id].text = data.result.response.toString();
                  > }
                  >
                  > private function onFault(error:Object, token:Object = null):void
                  > {
                  > //Handle your fault logic here ...
                  > }

                  I've found that when you try to stack up calls like this that the subsequent
                  calls don't generate a result event. The only way I could get it to work is
                  to wait for the first result to come back, then make the second call, etc.
                  Have you actually gotten this to work as shown above?


                  • 6. Re: Handling Result Values in Flex
                    VarioPegged Level 2
                    quote:

                    Have you actually gotten this to work as shown above?


                    Absolutely actually.

                    TS