3 Replies Latest reply on Oct 16, 2008 9:54 AM by ntsiii

    pesky loose coupling question

      Hey guys,
      I have 3 files: main.mxml, registration.mxml, and update.mxml. The registration is a custom canvas component with a datagrid, and the update is a popup activated by clicking the datagrid. I understand how to dispatch custom events, but I'm having trouble dispatching from popup back to main.mxml where my remote code is located. I can successfully dispatch objects with a custom event from reg component to main. What am I doing wrong? Should I just add a remote command in the registration component and run a function in the registration? Doesn't seem like loose coupling to me?
        • 1. pesky loose coupling question
          Karl_Sigiscar_1971 Level 3
          If your registration component is instantiated in main and you dispatch an event that bubbles from registration to main, then bubbling works. But forget about bubbling when dispatching an event from a popup to any other component. You can do the following:

          If you use a model (with Cairngorm, PureMVC ... or simply Singleton), you can have an object in your model that extends EventDispatcher and serves as a message target.

          package com.mycompany.core.model
          import flash.events.EventDispatcher;

          // ----------------------------------------------------------------------------------------- --
          // This class only serves as the target for messages that concern objects that are not
          // in the display list or that are in the display list but cannot be reached by event bubbling
          // ----------------------------------------------------------------------------------------- --

          public class MessageTarget extends EventDispatcher
          public function MessageTarget()


          In your model:

          // -----------------------------------------------------
          // Message target
          // -----------------------------------------------------

          public var messageTarget:MessageTarget = new MessageTarget();

          In any component interested in some messages (e.g column visibility) dispatched on the message target :

          // Add event listener for column visibility change
          this.model.messageTarget.addEventListener(ColumnVisibilityChangedEvent.COLUMN_VISIBILITY_ CHANGED, this.onColumnVisibilityChanged);

          Then, you can dispatch an event from anywhere that can be listened to anywhere:

          // Send Column Visibility Changed event

          new ColumnVisibilityChangedEvent(ColumnVisibilityChangedEvent.COLUMN_VISIBILITY_CHANGED, false, false));
          • 2. Re: pesky loose coupling question
            hoz Level 1
            At least I know that it's a function of the popup. I don't use a framework, so I assume I have two choices:

            1. Keep the pop up and write the functions including remote in the registration file
            2. Create a state with a canvas and dispatch event to the main

            Does that sound right?
            • 3. Re: pesky loose coupling question
              ntsiii Level 3
              You can create the "messageTarget" in a singleton class. the key is that the "model" is available anywhere.