1 Reply Latest reply on May 27, 2010 10:59 AM by Catalin Anastasoaie

    Local Connection Air to Air

    flexchief Level 1

      I am successfully able to communicate from my air app1 to app2 but can someone please advise me how to then communicate from app2 to back to app1?


      Here is my code:

       

      app1

       

              private function sendMessage(event:MouseEvent):void

              {

                  conn.send("app#LocalConnAir2:taskConnection", "localconnectionHandler", inputTask.text);

              }

       

      app2

       

                private function InitConn():void

                {

                      conn = new LocalConnection();

                      Alert.show(conn.domain);

                      conn.allowDomain("app#LocalConnAir1");

                      conn.client = this;

                      try

                      {

                          conn.connect("taskConnection");

                      }

                      catch (error:ArgumentError)

                      {

                          trace("Can't connect.");

                      }

                  }

       

      Many thanks

      Adam

      Flexchief

        • 1. Re: Local Connection Air to Air
          Catalin Anastasoaie Adobe Employee

          Hi Adam,

           

          I've modified the two applications that you provided to communicate between them vice-versa. Here is code from the two AIR applcitions:

           

          LocalConnAIR1

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initConn()">

              <mx:Script>

                  <![CDATA[

              import mx.controls.Alert;

                  import flash.net.LocalConnection;

           

           

                  private var connTo:LocalConnection;

                  private var connFrom:LocalConnection;

           

          private function initConn():void

          {

          initConnFromApp1();

          initConnToApp2();

          }

           

          private function initConnFromApp1():void

          {

                      connFrom = new LocalConnection();

                      Alert.show(connFrom.domain);

                      connFrom.allowDomain("app#LocalConnAir2");

                      connFrom.client = this;

                      try

                      {

                          connFrom.connect("taskConnectionApp2");

                      }

                      catch (error:ArgumentError)

                      {

                          trace("Can't connect.");

                      }

          }

           

                  private function initConnToApp2():void

                  {

                      connTo = new LocalConnection();

                      connTo.addEventListener(StatusEvent.STATUS, onStatus);

                  }

           

                  public function alertFromApp2():void

                  {

                      Alert.show("Message from App2");

                  }

           

                  private function sendMessageToApp2():void

                  {

                      connTo.send("app#LocalConnAir2:taskConnectionApp1", "alertFromApp1");

                  }

           

                  private function onStatus(event:StatusEvent):void

                  {

                      switch (event.level)

                      {

                          case "status":

                              Alert.show("LocalConnection.send() succeeded");

                              break;

                          case "error":

                              Alert.show("LocalConnection.send() failed");

                              break;

                      }

                  }

                  ]]>

              </mx:Script>

              <mx:Panel horizontalCenter="0" verticalCenter="0">

          <mx:Button label="sendMessageToApp2" click="sendMessageToApp2()" />

              </mx:Panel>

          </mx:WindowedApplication>

           

          LocalConnAIR2

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onInit()">

              <mx:Script>

              <![CDATA[

                  import mx.controls.Alert;

                      import flash.net.LocalConnection;

           

                  private var connTo:LocalConnection;

                  private var connFrom:LocalConnection;

           

           

          private function onInit():void

          {

          initConnFromApp1();

          initConnToApp1();

          }

           

                      private function initConnFromApp1():void

                      {

                          connFrom = new LocalConnection();

                          Alert.show(connFrom.domain);

                          connFrom.allowDomain("app#LocalConnAir1");

                          connFrom.client = this;

                          try

                          {

                              connFrom.connect("taskConnectionApp1");

                          }

                          catch (error:ArgumentError)

                          {

                              trace("Can't connect.");

                          }

                      }

           

                      private function initConnToApp1():void

                      {

                      connTo = new LocalConnection();

                      connTo.addEventListener(StatusEvent.STATUS, onStatus);

                      }

           

                      public function alertFromApp1():void

                      {

                          Alert.show("Message from App1");

                      }

           

                      private function clearTasks(event:MouseEvent):void

                      {

                      }

           

                      private function sendMessageToApp1():void

                  {

                      connTo.send("app#LocalConnAir1:taskConnectionApp2", "alertFromApp2");

                  }

           

                  private function onStatus(event:StatusEvent):void

                  {

                      switch (event.level)

                      {

                          case "status":

                              Alert.show("LocalConnection.send() succeeded");

                              break;

                          case "error":

                              Alert.show("LocalConnection.send() failed");

                              break;

                      }

                  }

           

                 ]]>

             </mx:Script>

              <mx:Panel horizontalCenter="0" verticalCenter="0">

          <mx:Button label="sendMessageToApp2" click="sendMessageToApp1()" />

              </mx:Panel>

          </mx:WindowedApplication>

           

          Hope this helps,

          -Catalin