1 Reply Latest reply on Jan 18, 2011 3:57 PM by oldMster

    HOW TWO SUB-APPLICATION IN SIBLING APPLICATION DOMAIN TALK ?

    zoozbee

      How two sub-application loaded in sibling application domain ( in same  security domain) can talk with each other ? Is there an example ?

       

      I want to pass a custom event from sub-application 'A' to sub-application 'B' . One way i am thinking to do is using mainApplication systemManager. Application 'A' with get the main application systemManager using  systemManager.getSandboxRoot() and dispatch event. Application B is listening for this event like

      systemManager.getSandboxRoot().addEventListener(
                          MyCustomEvent, customEventHandler, true);

      Marshelling of class should work because of customEvent is compiled with sub-app 'A' and 'B'.
      Also both sub-app are built using same version of flex.

      Will this work or is there any other approach ?


      Thanks,
      Zooz
        • 1. Re: HOW TWO SUB-APPLICATION IN SIBLING APPLICATION DOMAIN TALK ?
          oldMster Level 3

          The way we handle this is for the main application to have an array of objects to keep track of the custom events, and then each component registers with it.

           

          In each component that needs to listen for an event, in the 'Creation Complete' method we register it with the 'main' application.

           

          private function _Creation():void {

          FlexGlobals.topLevelApplication.customEvents.NamespaceChange.push(this);

          this.addEventListener("WebLab.namespaceChange",clearPatientLists);

          }

          In the main application:
          [Bindable] public var customEvents:Object = new Object();  //object to keep track of all objects that need custom events dispatched to them
          private function _Creation():void {
          ExternalInterface.call('setPlayerFocus');
          currentState = "staLogin";
          var temp:Array = new Array();
          customEvents.PatientChange=temp;
          var temp2:Array = new Array();
          customEvents.NamespaceChange=temp2;
          }
          and finally, in the component that 'generates' one of the custom events, the code that uses the registration info to dispatch the events:
          changeNamespace(something:String):void {
          ....
          ....
          ...
          for (var i:int = 0; i<FlexGlobals.topLevelApplication.customEvents.NamespaceChange.length ; i++) {
          FlexGlobals.topLevelApplication.customEvents.NamespaceChange[i].dispatchEvent(new Event("WebLab.namespaceChange"));
          }
          There may be a better method, but this works for us.
          Mark