1 Reply Latest reply on Nov 25, 2008 9:55 AM by Newsgroup_User

    RemoteObject Event Listener Problem

    UberError
      I have a remoteobject which makes calls to functions like so

      private function callRO(method:String, args:Object):void
      {
      this["m_ro." + method].addEventListener("result", function(event){roResultHandler(event, method)});
      this["m_ro." + method].addEventListener("fault", function(event){roFaultHandler(event, method)});
      this["m_ro." + method](args);
      }

      ... where m_ro is my RemoteObject

      I want to be able to cleanup the event listeners by removing them when the result (or fault) is retrieved... I'm not really sure how to do this since I'm passing multiple parameters

      I'm assuming it would be something like:

      this["m_ro." + method].removeEventListener("result", function(event){roResultHandler(event, method));

      (and almost the same for the fault)... but this does not work

      I need to pass in the second parameter to my handler because I want 1 function handle all results with a switch statement (based on the method).

      Any help would be greatly appreciated!
        • 1. Re: RemoteObject Event Listener Problem
          Level 7

          "UberError" <webforumsuser@macromedia.com> wrote in message
          news:ggh7pq$hvm$1@forums.macromedia.com...
          >I have a remoteobject which makes calls to functions like so
          >
          > private function callRO(method:String, args:Object):void
          > {
          > this["m_ro." + method].addEventListener("result",
          > function(event){roResultHandler(event, method)});
          > this["m_ro." + method].addEventListener("fault",
          > function(event){roFaultHandler(event, method)});
          > this["m_ro." + method](args);
          > }
          >
          > ... where m_ro is my RemoteObject
          >
          > I want to be able to cleanup the event listeners by removing them when the
          > result (or fault) is retrieved... I'm not really sure how to do this since
          > I'm
          > passing multiple parameters
          >
          > I'm assuming it would be something like:
          >
          > this["m_ro." + method].removeEventListener("result",
          > function(event){roResultHandler(event, method));
          >
          > (and almost the same for the fault)... but this does not work
          >
          > I need to pass in the second parameter to my handler because I want 1
          > function
          > handle all results with a switch statement (based on the method).

          Use a token instead. Since the token gets passed as part of the event, once
          the event has been dispatched and listened for, it cleans itself up:

          This post I wrote a week or so has links to the docs you'll need to get
          started:
          http://flexdiary.blogspot.com/2008/11/more-thoughts-on-remoting.html