1 Reply Latest reply on May 25, 2010 3:17 AM by flexchief

    AIR to AIR localconnection working only in one direction

    flexchief Level 1

      I have two simple air applications and i need to be able to send a message to the opposite app on the click of a button. My code works fine from app1 to app2 but i am getting the following error when trying to send a message from app2 to app1: Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.LocalConnection was unable to invoke callback returnMessageHandler. error=ReferenceError: Error #1069: Property returnMessageHandler not found on flash.net.LocalConnection and there is no default value.

       

      Here is my code:

       

      App1

       

      <?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;

       

                  public var conn:LocalConnection;
                       
                  public function initConn():void
                  {
                      conn = new LocalConnection();
                      conn.allowDomain("app#app2");
                      conn.addEventListener(StatusEvent.STATUS, onStatus);
                      //Alert.show(conn.domain);

       

                      try
                      {
                          conn.connect("returnConnection");
                      }
                      catch (error:ArgumentError)
                      {
                          trace("Can't connect.");
                      }
                  }    
         
                  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;
                      }
                  }

       

                  public function returnMessageHandler():void
                  {
                      Alert.show("Recieved return message from app2");
                  }
                 
                  public function sendMessage():void
                  {
                      conn.send("app#app2:taskConnection", "localconnectionHandler");
                  }                       
              ]]>
          </mx:Script>
          <mx:Button x="10" y="10" label="send message" click="sendMessage();"/>
      </mx:WindowedApplication>

       

       

      App2

       

      <?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;

       

                public var conn:LocalConnection;

                public function InitConn():void
                {
                      conn = new LocalConnection();
                      conn.addEventListener(StatusEvent.STATUS, onStatus);
                      conn.allowDomain("app#app1");
                      conn.client = this;
                      //Alert.show(conn.domain);

       

                      try
                      {
                          conn.connect("taskConnection");
                      }
                      catch (error:ArgumentError)
                      {
                          trace("Can't connect.");
                      }
                  }

       

                  public function onStatus(event:StatusEvent):void
                  {
                      switch (event.level)
                      {
                          case "status":
                              Alert.show("LocalConnection.send() succeeded");
                              break;
                          case "error":
                              Alert.show("LocalConnection.send() failed");
                              break;
                      }
                  }

       

                  public function localconnectionHandler():void
                  {
                      Alert.show("Recieved message from app1");
                  }

       

                  public function sendReturnMessage():void
                  {
                      conn.send("app#app1:returnConnection", "returnMessageHandler");
                  }
              ]]>
          </mx:Script>
          <mx:Button x="10" y="10" label="send return message" click="sendReturnMessage()"/>
      </mx:WindowedApplication>

       

       

      If anyone can plese help me figure this out I would greatly appriciate it I'm tearing my hair out!

       

      Thanks

      Adam

      Flexchief