3 Replies Latest reply on Jan 7, 2009 10:38 AM by ntsiii

    Importing from a database

    SiHoop Level 1
      I cannot return a value from a database to Flex. I call a function (i.e. importText) which sends a request to a php page. When the data return to Flex I use an event listener to manage the returned data, but then have a problem. Clearly, using
      return xxx
      sends a value back to the function, but it does not contain the required information.
      How should I return the returned data back to the original function call?
        • 1. Re: Importing from a database
          Level 7

          "SiHoop" <webforumsuser@macromedia.com> wrote in message
          news:gk0qjl$mh8$1@forums.macromedia.com...
          >I cannot return a value from a database to Flex. I call a function (i.e.
          > importText) which sends a request to a php page. When the data return to
          > Flex I
          > use an event listener to manage the returned data, but then have a
          > problem.
          > Clearly, using
          > return xxx
          > sends a value back to the function, but it does not contain the required
          > information.
          > How should I return the returned data back to the original function call?
          >
          > public function init():void{
          > var xxx:Array=importText("5")
          > trace("xxx="+xxx)
          > }
          > public function importText(_value:String):Array{
          > params.passageId = _value
          > service = new HTTPService();
          > service.url = " http://localhost/slashTest/login.php";
          > service.method = "GET";
          > service.addEventListener("result", httpResult);
          > service.send(params)
          > return xxx
          > }
          > public function httpResult(event:ResultEvent):void{
          > xxx=event.result.returnVal
          > }

          Try:

          private var xxx:Array;

          public function init():void{
          importText("5");
          }
          public function importText(_value:String){
          params.passageId = _value
          service = new HTTPService();
          service.url = " http://localhost/slashTest/login.php";
          service.method = "GET";
          service.addEventListener("result", httpResult);
          service.send(params);
          }
          public function httpResult(event:ResultEvent):void{
          xxx=event.result as Array;
          trace(event.result);
          trace(xxx);
          }

          Do you mind if I use your original code in my FAQ? I am seeing essentially
          this same question about once a day now.


          • 2. Re: Importing from a database
            SiHoop Level 1
            Thanks for the reply. I'm pleased you will be able to use the case in your FAQs.
            • 3. Re: Importing from a database
              ntsiii Level 3
              Understand that all Flex data service calls are asynchronous, so you can never access the result in the same function that you invoke send, as you tried with:
              service.send(params)
              return xxx;

              You will need to wait until the result handler is called before you can access the result.

              Tracy