3 Replies Latest reply on Sep 23, 2010 2:42 PM by Devtron

    custom event handler


      I have an application that consists of a main app, a component (mxml component) which is a second "screen" of the application. The component has a data grid (rendered with another mxml renderer custom component) which contains some data, and I want to fire a custom event when I click on a row of the data grid. So far so good. I have built the custom event, and the renderer, and I've added a click listener on the datagrid. I need the click listener to then fire my custom event, which it appears to do. The only problem is that the event handler for the custom even resides in the main view(not the component where the datagrid resides, although I've tried that). I have added a meta tag with the name of the custom event to the renderer page since that is where the custom event is dispatched and I've added the renderer component with a reference to the meta tag and directed the response to the handler subroutine in the main view. I can watch the execution in debug and everything works but the handling of the dispatch event. Here is some code snippets:


      On the main page I have the handler:


      protected function workorderSelectedHandler(Event:WorkorderEvent):void


           Alert.show("Event fired.");



      and in the mxml portion:


      <renderers:WorkorderRenderer id="worenderer" selectWorkorder="workorderSelectedHandler(event)" visible="false"/>

      of course I have mx:renderers set in the application tab


      In the renderer component I have a meta tag:



      [Event(name="selectWorkorder", type="events.WorkorderEvent")]



      and in the datagrid select handler I have:


      var eventObject:WorkorderEvent = new WorkorderEvent("selectWorkorder", wo);



      I can watch it get to the dispatchEvent and then enter my custom "WorkorderEvent", but it never hits the workorderSelectedHandler() in the main app. What am I doing wrong?

        • 1. Re: custom event handler
          Devtron Level 3

          are you adding the listener event?


          you may need to add it to your grid, during MXML initialization.


          try something like:

          mydatagrid.addEventListener(my_event_type_here, my_event_function_here);

          • 2. Re: custom event handler
            ccrum Level 1

            Well, the custom renderer has a listener for the click. Then that in turn fires a custom event with the dispatchEvent. I'm getting the data I need in the first event, but it is "sitting" in the custom event. I guess what I need to know is where to put the event handler for the custom event. I have another custom event that works almost exactly the same way, and it has no "listener" per se. It has a Metadata tag that ties it back to the main app via a component list exactly like the code above. I thought the listing in the component tag on the main page was the "listener" for the dispatchEvent. Am I mistaken?

            • 3. Re: custom event handler
              Devtron Level 3

              ^ it may be, I am no expert in this area. It seems to me that you have an event, which WATCHES for results. but technically, you have not added it as a

              ListenerEvent, it is just a regular event. Atleast that's my take on it. I could be wrong.


              Do you explicitly assign a ListenerEvent anywhere? I dont see it. Refer to my first post.