3 Replies Latest reply on Jan 28, 2010 10:21 AM by Dazed&Flashed

    dispatch custom event from itemClick handler

    e11137

      hi,

      I'm trying to dispatch a custom event from my itemClick handler.

      So when I click on an item of my datagrid, I want to send a custom event.

       

      private function dataGridItemClickHandler( event:ListEvent): void

      {

           dispatchEvent( new myEvent( myEvent.NEW, values[event.columnIndex]["name"]) );

      }

       

      <mx:DataGrid dataProvider="{values}" itemClick="dataGridItemClickHandler(event)">

      ...

      </mx:DataGrid>

       

      but this code doesn't work.

       

      Can you help me

       

      thanks

       

      best regards

       

       

       

       

       

        • 1. Re: dispatch custom event from itemClick handler
          Gregory Lafrance Level 6

          How does your code not work? Can you give more details on what is happening and what is not working?

          • 2. Re: dispatch custom event from itemClick handler
            archemedia Level 4

            Where did you attach your event listener for the myEvent.NEW event?

             

            Dany

            • 3. Re: dispatch custom event from itemClick handler
              Dazed&Flashed

              Please see that you override the function clone() and return the new function.If that is correct.you can call the super() method to initialize your base class.

               

              If your custom event {myEvent} is in package say: CustomEvent,

               

              1)import package CustomEvent.myEvent

               

              2) keep in <mx:metadata>[Event(name="NEW", type="CustomEvent.myEvent")]</mx:metadata>.. name suggest  what type of event you want

               

              3)Create an itemclick listener and in dataGridItemClickHandler

               

              private function dataGridItemClickHandler( event:ListEvent): void

              {

               

                   dispatchEvent( new myEvent( ' NEW ', values[event.columnIndex]["name"]) );

               

              }

               

              private funcation myEventListener(evt:myEvent):void

              {

              //Put your logic

              }

               

              4)Use this event by name NEW="myEventListener(event)"  this will behave as event type in the datagrid tag like click, hover and others.

               

              Hope this helps! Please excuse if anything is logically incorrect.Do point out.Thanks.