8 Replies Latest reply on Jul 2, 2010 10:58 AM by =VA=FyreHeart

    Event catch22

    =VA=FyreHeart Level 2

      I guess I don't understand events that well, so I hope one of you can help.

       

      It seems to me that a component already has to respond to an event before it can dispatch it.

       

      I'm trying to extend a component that doesn't respond to MouseEvents so that it will. Specifically, I'm trying to get an AdvancedDataGridColumn to respond to a mouse click.

       

      Here's my extension code:

           import flash.events.*;
          import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

       

          [Event(name='click', type='flash.events.MouseEvent')]
         
          public class AdvancedClickableColumn extends AdvancedDataGridColumn {
              public function AdvancedClickableColumn(columnName:String=null) {
                  super(columnName);
              }
          }

       

      And MXML:

                       <myns:AdvancedClickableColumn ...blah... click="handleClick(event)"/>

       

      This does nothing. The handleClick routine is never called. Where am I supposed to dispatch the MouseEvent.CLICK event? It seems like I need something in the class definition like:

      private function onMouseClick(event:MouseEvent):void {

           dispatchEvent(flash.events.MouseEvent.CLICK);

      }

      ...but that would require it to already respond to mouse events, which is the whole point.

       

      What am I missing?

        • 1. Re: Event catch22
          Dajji Level 3

          I believe you need to study events little more. All you need to do is write following code in your mxml. This will call the event handler and you can perform whatever you want to.

           

          <mx:Script>
               <![CDATA[
                    private function handleClick(e:MouseEvent):void{
                         //Write your code here.
                    }
               ]]>
          </mx:Script>
          

          • 2. Re: Event catch22
            =VA=FyreHeart Level 2

            Naturally, I already wrote the handleClick() function. I thought that went without saying.

             

            As I mentioned above, the handleClick() function is never called. I've added breakpoints and Alerts in the function, but neither fires. I can't tell any change in behavior from implementing my new class definition.

            • 3. Re: Event catch22
              rtalton Level 4

              I think what you are trying to do is possible, but I've never tried it because I can use the existing events to do pretty much anything with the ADG.

              Are you doing something for which the existing events cannot be utilized? (itemClick, itemDoubleClick, headerRelease, these may help you)

              1 person found this helpful
              • 4. Re: Event catch22
                VRPDeveloper Level 3

                You ar e not dispatching event properly.... You need to do in this way

                 

                dispatchEvent(new Event("click"))

                      OR

                var eventObj:MouseEvent= new MouseEvent("click");
                dispatchEvent(eventObj);

                Hope you got it!!!
                • 5. Re: Event catch22
                  =VA=FyreHeart Level 2

                  itemClick and itemDoubleClick look like they may work. I didn't find them earlier b/c I was expecting them to be tied to the column, not the ADG itself. Thanks for the tip!

                  • 6. Re: Event catch22
                    =VA=FyreHeart Level 2

                    VRP - thanks for the tip. You're right, my dispatchEvent() syntax is wrong, but the crux of my question is where should the dispatchEvent() call go in the first place? The code above requires a mouse event to dispatch a mouse event, but the lack of support for mouse events is the problem I'm trying to solve.

                    • 7. Re: Event catch22
                      VRPDeveloper Level 3

                      Either you can create custom event and then use that event in AdG or you can use itemClick events to do default thing....

                       

                      Any Helpful answere should be marked as Helpful...

                      • 8. Re: Event catch22
                        =VA=FyreHeart Level 2

                        VRP - thanks again, but you're still not understanding my question. Where in the following class definition does the dispatchEvent() call go?

                         

                        public class AdvancedClickableColumn extends AdvancedDataGridColumn {
                             public function AdvancedClickableColumn(columnName:String=null) {
                                  super(columnName);
                             }
                        }

                         

                        To say it another way, how to I write a function that will dispatch mouse click events?


                        Or is [Event(name='click', type='flash.events.MouseEvent')] supposed to be enough? (Because that doesn't seem to work.)