0 Replies Latest reply on Oct 15, 2009 7:54 PM by bshan-yu

    can't set public Object in HTTPService result listener

    bshan-yu

      Hello.

      I am using a data object class.  The class is based on a class that contains the HTTPService calls.  I want to return the event.results to the local instance of the class by setting a public Object = the results Object. However, the public object is null after the HTTPService event result listener function is finished.

       

      It is easier to see than to describe:

       

      In the main application. i make an instace of my activity class:

      myactivity:activity = new activity() ;

       

      now, I invoke the getdata method:

       

      myactivity.getdata() ;

       

      The getdata() method fails at runtime, because it tries to reference the results object.

      See the base class and the activity class below.

       

       

      BASECLASS: (just the main parts are listed here):

      public class transferObject
          {
              public var baseurl:String ;
              public var dbresult:Object =new Object();
              public var service:HTTPService ;
             
              public function transferObject()
              {
              geturl("ghost") ;
              }
             
              public function geturl(db:String) : void
              {
                      baseurl = "https://xyzzy/" ;
                          }
             
              public function getHttpService(methodname:String):void {
                      service = new HTTPService();
                      service.url = this.baseurl + methodname;
                      service.channelSet ;
                      service.method = "POST";
                      service.addEventListener("result", httpResult );
                      service.addEventListener("fault", httpFault);
                      service.send();
                                
                  }

       

       

       

                 public function httpResult(event:ResultEvent):void {
                      dbresult = event.result ;

      //DBRESULT IS THE OBJECT I WANT TO REFERENCE IN THE DERIVED CLASS

                   //Do something with the result.
                  }

       

                  public function httpFault(event:FaultEvent):void {
                      var faultstring:String = event.fault.faultString;
                      Alert.show('Error sending data: '+faultstring+' '+event.fault);
                  }

       


          }

       

      HERE IS THE DERIVED CLASS:

      package dataObjects
      {
                    
         
          public class activity extends transferObject
          {
          import mx.controls.Alert ;   
      [Bindable]
      public var event_id:String ;
      [Bindable]
      public var description:String ;

       

             public function activity()
              {
                  super();
              }
             
              public function getdata():void
              {
                  getHttpService("eventually.sendtest") ;

       

                this.event_id = dbresult.result.activities.activity.getItemAt(0).event_id ;

      ----> THE LINE ABOVE FAILS AT RUN TIME BECAUSE THE DBRESULT OBJECT IS NULL

       

      }
             
                                 }

       

       

       

      THANK YOU FOR ANYHELP YOU CAN PROVIDE