3 Replies Latest reply on May 16, 2007 5:19 AM by ashar2005

    Dispatch module events to shell ?

    ashar2005
      I am trying to figure out if there is a way to dispatch a custom event from a module
      loaded with mx:moduleloader to the shell application that loaded the module.

      I have tried putting the [Event(type="myEventType")] inside of the mx:MetaData tag of the Module
      and dispatching the event, but can't get the shell application to receive the dispatched event
      from the module.

      I have tried several things, including adding an event listener...
      myModuleName.addEventListener(myEventType, myEventFunction)
      in the shell, but it doesn't receive the event when the module dispatches it.

      TIA...
        • 1. Re: Dispatch module events to shell ?
          peterent Level 2
          Check my blog: http://weblogs.macromedia.com/pent and seach for Module.
          • 2. Re: Dispatch module events to shell ?
            ashar2005 Level 1
            Thanks for the reply, I've read that before, but it doesn't help the problem.
            It does not cover anything about dispatching "custom" events, only
            the standard module loading events that tell the state of the module
            being loaded, such as the "ready" event in your example.

            I need to dispatch an event from a Module that is already loaded and being used.
            When the user clicks on a button in the module, dispatch an "prodAdded" event or some other name,
            same for other functions. Normally you can attach those listeners in the tag with
            the component as long as they are declared in the component with an [Event] as metadata
            and then put the listener in the call to the tag i.e.
            <v:Customcomponent width="100%" added="addFunction()" deleted="delFunction()"/>
            however you cannot attach those listener attributes to a ModuleLoader tag even though the Module
            may have an [Event] tag inside Metadata tags, it throws an error. I even tried putting "bubbles="true"
            on the event declaration, hoping it would bubble to the shell application, but still no success.

            • 3. Re: Dispatch module events to shell ?
              ashar2005 Level 1
              I figured it out.

              1. Since you cannot attach the events listener to the <mx:ModuleLoader> tag like you can for a custom component
              you must add the listener with actionscript. moduleName.addEventListener('eventName', functionToRun);

              2. Within the module set the bubbles parameter to "true" on your dispatchEvent call so the shell application receives it.
              this.dispatchEvent('eventName', true)

              I was putting the bubbles setting in the Modules Event declaration.

              It works as expected now.