1 Reply Latest reply on Aug 25, 2007 3:35 PM by DEfusion

    Having issues with custom events

    DEfusion
      I'm trying to figure out this issue I'm having using custom events, I've read all the documentation & tutorials I can find and this bit still makes no sense.

      I have the following setup:

      LoginForm: custom component (which is created as a popup via the PopupManager)
      ApplicationHeader: custom component (which is added to the application in MXML)
      application: creates the LoginForm as a popup via the PopupManager, has the ApplicationHeader defined in the MXML.

      When a user logs in the LoginForm dispatches a custom event, there are two listeners defined:

      1. In the application:

      private function showLoginForm() : void {
      var loginForm:LoginForm = LoginForm( PopUpManager.createPopUp(this, LoginForm, true) );
      loginForm.addEventListener( UserLoggedInEvent.USERLOGGEDINEVENT, userLoggedInHandler );
      }

      2. In the ApplicationHeader custom component:

      private function init():void {
      parent.addEventListener( UserLoggedInEvent.USERLOGGEDINEVENT, userLoggedInHandler );
      }

      When the event is dispatched the application listener picks it up as expected, however the listener inside the custom component never sees it - even though the event is set to bubble.

      The only way I've managed to get this to work is to do the following in the application:

      private function userLoggedInHandler( event:UserLoggedInEvent.USERLOGGEDINEVENT ):void {
      // .. logic for handling the event
      // re-dispatch the event
      dispatchEvent( event );
      }

      This makes no sense at all, what if I didn't want the application to handle the event itself. There is a line in the event documentation
      that says "You can only register an event listener with an object if that object dispatches the event." that might explain it, but it still makes no sense.

      Any help/advice/examples would be more than helpful as I'm pulling my hair out here.