2 Replies Latest reply on Oct 26, 2009 4:07 PM by timo888

    Is this event dispatch legal in Flex AIR?

    timo888 Level 1

      My main app is listening for two events:

       

      GotArgsEvent   // raised by a dialog that asks users what to search for

       

      GotDataEvent // raised by the query after it fetches data from the database based on the user's input

       

      The object that raises the GotData event is instantiated in the eventhandler for the GotArgs event:

       

      private function GotArgsEventHandler(e:GotArgsEvent): void {

      // note: class Query extends EventDispatcher

      // note also that Q is declared at the top of the main app as var Q:Query;

        Q  =new Query(e.args);

      }

       

       

      private function GotDataEventHandler(e: GotDataEvent): void {

      grid.dataProvider= e.myArrayCollection;

      }

       

       

      HOWEVER, the main app never hears the GotData event . Although query Q does appear to be invoking eventDistpatch, I'm not sure the event is actually being dispatched. What Flex/AS class should I enter below if stepping through the code:

       

      public class myQueryClass extends EventDispatcher  {

      ...

      private function foo():void {

      var eventObj:GotDataEvent = new GotDataEvent ( "GotDataEvent", someData, true, false );

      this.dispatchEvent(eventObj);  // into which Flex class  should the debugger take me when stepping into from here?

      }

      }

       

      Is it illegal to instantiate an object that extends EventDispatcher when you're inside an eventhandler?

      Thanks

        • 1. Re: Is this event dispatch legal in Flex AIR?
          paul.williams Level 4

          Only events from objects on the display-list will bubble up. Since your Query object is not on the display-list, the event it dispatches will not bubble up to your application. In order to handle events from your Query object you will need to add an event listener to it directly. You could do this in your PopUp when you create your Query object and then redispatch the GotDataEvent from the PopUp. Something like:

           

          private function GotArgsEventHandler(e:GotArgsEvent): void {

          // note: class Query extends EventDispatcher

          // note also that Q is declared at the top of the main app as var Q:Query;

            Q  =new Query(e.args);

            Q.addEventListener( "GotDataEvent", handleGotDataEvent );

          }

           

          private function handleGotDataEvent( event : Event ) : void

          {

               dispatchEvent( event );

               Query( event.target ).removeEventListener( "GotDataEvent", handleGotDataEvent );

          }

           

          Make sure you override the 'clone' method in your custom event.

          • 2. Re: Is this event dispatch legal in Flex AIR?
            timo888 Level 1

            Thanks very much for the help, Paul.