3 Replies Latest reply on Mar 27, 2009 3:13 PM by vaniacampos

    listening Events


      Hello World:

      I have a big problem. I hope that you may help me =[

      * Well, i´m working with adobe Flex 3 and flex Builder.
      * When i need data stored in database, i use web services.

      * Then i have a class that manipulate call and reception of information delivered by web services: manipulateWS.as
      * when data arrives i launch event for alert to form that need it.

      * Each form has its own class manipulateWS.as ....
      * Many forms can call to the same method (ej: loadCountry of class manipulateWS.as)

      * when the forms ask data, call manipulateWS.as's method and when data arrive it listen event.

      Although each form has its own class manipulateWS.as, all listen when the data arrive, even when it dont call it.
      Then the form does incorrect things, because it listen event for other form.....


      Finally my question is: How can i avoid this situation? How do event know who call it ? or How do event know whom answer it?


      Thank you in advance.....
      greetings!!!

      Here is part of code, for you understand better my problem....

      **********************************************************
      ********* manipulateWS.as ***************
      **********************************************************

      //register listener of web service's method
      ws.loadCountry.addEventListener(ResultEvent.RESULT, resultLoadCountry);

      //method for ask for information:
      public function loadCountry(idCountry:int):void
      ws.loadCountry(idCountry);

      //method for manipulate the results:
      private function resultLoadCountry(event:ResultEvent):void
      {

      //when data arrive... i launch a event for alert that information is here
      var ev:ResultMethodWSEvent;
      ev = new ResultMethodWSEvent("resultLoadCountry",true, "");

      dispatchEvent(ev);
      }

      *************************************************************************
      The class ResultMethodWSEvent.as extends of event, and it need:
      - str_nameMethod: the name of method-> resultLoadCountry
      - if result Ok or not -> true or false
      - aditional data (optional)

      *************************************************************************

      **********************************************************
      ********* FormX.mxml ***************
      **********************************************************
      //register listeners:
      my_managerWS.addEventListener(ResultMethodWSEvent.RESULTADOWS, manipulateResultMethodWS);

      //manipulating event:
      private function manipulateResultMethodWS(ev:ResultMethodWSEvent):void
      {
      switch(ev.str_nameMethodWS)
      {
      case 'resultLoadCountry': //do things...
      }
      }

      //when i need information:
      my_managerWS.loadCountry(idCountry);



      **********************************************************
      ********* FormY.mxml ***************
      **********************************************************
      //register listeners:
      my_managerWS.addEventListener(ResultMethodWSEvent.RESULTADOWS, manipulateResultMethodWS);

      //manipulating event:
      private function manipulateResultMethodWS(ev:ResultMethodWSEvent):void
      {
      switch(ev.str_nameMethodWS)
      {
      case 'resultLoadCountry': //do OTHERS things...
      }
      }
      //when i need information:
      my_managerWS.loadCountry(idCountry);

      *****************************************************************
        • 1. Re: listening Events
          Gregory Lafrance Level 6
          The event object passed into the event handler will have the target and currentTarget properties, which you can use to know which button was clicked, or even the container of the button that was clicked.

          In your case, you might want to dispatch a custom event, that way you can pass information into the event object, such as a keyword indicating the name of the form that is making the request.

          See these FB3 help sys topics:

          Dispatching custom events
          Defining events in ActionScript components
          Manually dispatching events
          • 2. Re: listening Events
            Level 7

            "vaniacampos" <webforumsuser@macromedia.com> wrote in message
            news:gqgnu5$1on$1@forums.macromedia.com...
            > Hello World:
            >
            > I have a big problem. I hope that you may help me =[
            >
            > * Well, i´m working with adobe Flex 3 and flex Builder.
            > * When i need data stored in database, i use web services.
            >
            > * Then i have a class that manipulate call and reception of information
            > delivered by web services: manipulateWS.as
            > * when data arrives i launch event for alert to form that need it.
            >
            > * Each form has its own class manipulateWS.as ....
            > * Many forms can call to the same method (ej: loadCountry of class
            > manipulateWS.as)
            >
            > * when the forms ask data, call manipulateWS.as's method and when data
            > arrive
            > it listen event.
            >
            > Although each form has its own class manipulateWS.as, all listen when the
            > data
            > arrive, even when it dont call it.
            > Then the form does incorrect things, because it listen event for other
            > form.....

            Look at tokens

            http://flexdiary.blogspot.com/2008/11/more-thoughts-on-remoting.html

            There's some example code showing that with AMFPHP in the Lazy Loading Tree
            example. Web services will be slightly different, but you should be able to
            get the general concept.


            • 3. Re: listening Events
              Level 1
              Thank you for your replies and ideas!!!!
              I´m going to study that solution!!!!

              Thanks again!