9 Replies Latest reply on Nov 21, 2006 11:54 AM by ntsiii

    ResultEvent Behavior

    jfillman Level 1
      This has me completely baffled. I have a view with a username and password textinput boxes and a button that calls a PHP functions to query MySQL. It doesn't matter what I put in the username and password boxes (including completely blank fields), Flex always changes states.

      private function onResultLogin(event:ResultEvent):void {
      currentState = 'Desktop';
      }

      Here is the PHP:

      public function login($username, $password) {
      $username=$this->mysqli->real_escape_string(trim($username));
      $password=$this->mysqli->real_escape_string(trim($password));
      if (!$result=$this->mysqli->query("SELECT * from appusers WHERE username='$username' AND password = sha1('$password')")) {
      $msg=$this->err_prefix."SELECT query error: ".$this->mysqli->error;
      $this->mysqli->close();
      throw new Exception($msg);
      }
      if ($result->num_row>0)
      return true;
      }

      I can't figure out why the PHP function is always returning a result to Flex.

      I'd also like to know how to see what the PHP function is returning to Flex.
        • 1. Re: ResultEvent Behavior
          ntsiii Level 3
          I don't know PHP, so take that into account.

          The onResultLogin will be called every time you successfully call the php service, regardless of the content of the result. So you will always switch to "Desktop" when you do a send. Only if there is a hard fault, will the result handler not be called.

          The data returned by the call is located in the result object:
          event.result;

          Exactly what it is depends on the resultFormat of the data service call. What Dataservice are you using(HTTPService, Webservice, RemoteObject)?

          What is that PHP function returning? I advise you use XML to pass data around. It is the most easy to debug.

          Tracy
          • 2. Re: ResultEvent Behavior
            jfillman Level 1
            I'm using RemotObject. How can I see what is getting returned in the event.result object? I tried trace(event.result); but it never displays anything.

            Preferably, I'd like to do a check in Flex as to whether "true" is returned. If it is, change to the Desktop state, if not, got to a different state. I just can't figure out the syntax to do this.

            • 3. Re: ResultEvent Behavior
              ntsiii Level 3
              Your approach is correct. All you need to do is to be able to access the data in the result object.

              RemoteObject is almost certainly defaulting to mx:Object. Unfortunately, Object is a bit difficult to debug compared to xml.

              Are you using Flex Builder, where you can examine the contents of result in real time?

              If not then it is trial and error to figure out the actual structure of the result object. Or you might find a "dumper" that will read out the contents of an object.

              It looks like the PHP is returning a boolean? Maybe you can change the result format="string" (?text? You'll need to check the docs)

              If it was me, I would change the php to return an xml string:
              if ($result->num_row>0)
              return <status>true</status>";
              else
              return <status>false</status>";

              then set resultFormat="e4x",
              then in the result handler do:
              var sStatus:String = XML(event.result).text().toString(); //will be "true" or "false"

              Tracy
              • 4. Re: ResultEvent Behavior
                jfillman Level 1
                Tracy,

                I am using Flex Builder, but really just started with it last week, so am not up on all it's features.

                I'm not quite sure what it is this line does and where you are suggesting it should be.

                then set resultFormat="e4x",

                Jason
                • 5. Re: ResultEvent Behavior
                  ntsiii Level 3
                  resultFormat is a property of all of the data sevice classes. It determines how the result data from the call will be stored in Flex. The default is Object, but e4x is the latest and greatest XML object(node).

                  You should use this if at all possible.

                  If you want to try, post back and I'll help.

                  Tracy
                  • 6. Re: ResultEvent Behavior
                    ntsiii Level 3
                    If you want you can debug the data call in Flex Builder, and look at the result object directly in the watch panel..
                    • 7. Re: ResultEvent Behavior
                      jfillman Level 1
                      The Console Panel only returns this, whether I use a username and password or not:

                      ReferenceError: Error #1056: Cannot create property isError on mx.messaging.AcknowledgeMessage.
                      • 8. Re: ResultEvent Behavior
                        jfillman Level 1
                        Missed one line. It also returns "null".
                        • 9. Re: ResultEvent Behavior
                          ntsiii Level 3
                          Your php looks like it is returning a boolean. I don't think this is a good idea, especially if you are having trouble. Flex handles strings, xml, objects. Try a string.

                          Tracy