2 Replies Latest reply on Jul 27, 2006 8:46 AM by dimival

    Help with the event flow!!!

    dimival Level 1
      I am having troubles when dispatching and listening to events in my application, can i dispatch events from an object that is not on the display list and have a display object to listen to that event?
      I am doing the following, i have a DataGrid componente listening for an event that it is dispatched from a non visual object; the event contains info about the new dataProvider for the DataGrid, here is the code:

      Component with the DataGrid
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" width="550" height="600"
      showCloseButton="true" close="PopUpManager.removePopUp(this)">
      import com.legosoft.events.DataProviderChangeEvent;
      import mx.managers.PopUpManager;

      public function manejaEvento(event:DataProviderChangeEvent):void
      pickListResult.dataProvider = event.newDataProvider;


      <mx:DataGrid id="pickListResult" width="100%" height="50%"
      creationComplete="pickListResult.addEventListener('newDataProvider', manejaEvento)">

      Here is the class that dispatches the event

      public class GetTiposFacultadesCommand extends EventDispatcher implements Command, Responder
      public function execute(event:CairngormEvent):void
      var delegate:BusinessDelegate = new BusinessDelegate(this);

      public function onResult(event:* = null):void
      var _dataModelEvent:DataProviderChangeEvent = new DataProviderChangeEvent('newDataProvider', false, false);
      _dataModelEvent.newDataProvider = event.result.toArray();

      public function onFault(event:* = null):void

      The thing is that the DataGrid never receives the event, i have no idea why it's not working. Can anyone help me out???
        • 1. Re: Help with the event flow!!!
          inlineblue Level 1
          In your code, you're listening to the grid for the "newDataProvider" event. That's wrong. The grid never dispatches a "newDataProvider" event. You need to listen to the dispatcher of the event, namely the instance of GetTiposFacultadesCommand that you've declared somewhere.
          • 2. Help with the event flow!!!
            dimival Level 1
            The point is that i dont want to have to pass the instance of the GetTiposFacultadesCommand to catch the event. The point is to send an event anywhere and be able to catch it anywhere in the application.
            I found a solution to this, i created my own EventDispatcher object as a singleton in the application, whenever i want to send an event and be able to catch it anywhere, i get the instance of this object and have it to send the event, wherever i want to catch it i get the instance of this object and have it to listen to it, in other words the EventDispatcher object i coded is a generic object that will send and receive the events, allowing others to get this instance and do something about the event.
            This object has a getInstance() method that returns the instance of this object, remember that this is a singleton so there's only one instance of it in the whole application, any object can get this instance and send/receive an event.