2 Replies Latest reply on Nov 14, 2006 2:14 PM by dr_ross

    Data from ResultEvent

    dr_ross Level 1
      hi all,
      I'm having trouble referencing data retrived via HTTPService listener and ResultEvent.
      The DataGrid i've plugged into the HTTPService works fine, but i can't seem to access the individual variables inside the lastResult object properly.

      Heres my code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical" creationComplete="userRequest.send()">
      Label {

      import mx.core.Application;
      import events.LoginEvent;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.soap.WebService;
      import mx.rpc.http.HTTPService;
      import mx.controls.Alert;
      import mx.rpc.events.FaultEvent;
      import flash.net.URLLoader;
      import flash.net.URLRequest;
      import flash.net.URLVariables;
      import flash.events.Event;

      public function checkUser():void



      private function checkUser_listener(event:ResultEvent):void
      <mx:HTTPService id="userRequest" url="check1.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <username>{username.text}</username><password>{password.text}</password><emailaddress>{em ailaddress.text}</emailaddress>
      <mx:Form x="22" y="10" width="493" height="331">
      <mx:Label text="Username"/>
      <mx:TextInput id="username"/>
      <mx:Label text="Password"/>
      <mx:TextInput id="password"/>
      <mx:Label text="Email Address"/>
      <mx:TextInput id="emailaddress"/>
      <mx:Button label="Submit" click="checkUser()"/>
      <mx:DataGrid id="dgUserRequest" dataProvider="{userRequest.lastResult.users.user}">
      <mx:DataGridColumn headerText="User ID" dataField="userid"/>
      <mx:DataGridColumn headerText="User Name" dataField="username"/>
      <mx:DataGridColumn headerText="Password" dataField="password"/>
      <mx:DataGridColumn headerText="Email" dataField="emailaddress"/>
      <mx:TextInput id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>
      <mx:Text text="v1.28"/>

      As you can see in the "checkUser_listener" function i'm trying to acces the username variable, used fine in the dataGrid, but i can't seem to get the syntax right. Any help would be much appreciated. Cheers, Dr_ross
        • 1. Re: Data from ResultEvent
          ntsiii Level 3
          First, using addListener is ok, but mor complicated than necessary. As you have it, there is no listener when the service is called the first time, on creationComplete, and I am pretty sure it is too late to have if after the send in the checkUser() function.

          Instead just specify the handler in the HTTPService tag:
          result="checkUser_listener(event)" (note the "event" arg, it is critical)
          That takes care of that once and for all.

          Second, specify resultFormat="e4x". I think the default is mx:OBject and is harder to work with that xml.

          Third, don't use lastResult in a handler, it is for binding expressions only.

          Instead do:
          private function checkUser_listener(event:ResultEvent):void
          var xmlResult:XML = XML(event.result);
          Alert.show(xmlResult.toXMLString()); //you shuld see your xml.

          • 2. Re: Data from ResultEvent
            dr_ross Level 1
            you sir/madam are a star, thanks for that. works like a charm, thanks for the help.