0 Replies Latest reply on Apr 10, 2012 9:34 AM by Rick.Blacker

    Using LocalConnection is not working. Help?

    Rick.Blacker

      Hi all,

      Trying to use LocalConnection so that I can send data between to air applications running on the same computer. I've looked all over the net for examples and have found many, but my app just does not work. Was hoping that someone might see what is wrong with my code.  I'm just posting the script section from each MXML file.  The two air applications are called ComSender and ComReceiver

       

       

      ComSender

      ================================================================

       

      <![CDATA[

                import mx.controls.Alert;

                import mx.events.FlexEvent;

                private var conn:LocalConnection;

       

                protected function init( event:FlexEvent ):void

                {

           btnSend.addEventListener( MouseEvent.CLICK, btnSend_Click );

           conn = new LocalConnection( );

           conn.addEventListener( StatusEvent.STATUS, onStatus );

                }

       

       

                private function btnSend_Click(event:MouseEvent):void

                {

           conn.send( 'app#ComSender:myConnection', 'showThis' );

                }

       

       

                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;

           }

                }

      ]]>

       

       

       

      ComReceiver

      ================================================================

      <![CDATA[

                import mx.controls.Alert;

                import mx.events.FlexEvent;

       

                private var conn:LocalConnection = new LocalConnection();

       

                protected function init( event:FlexEvent ):void

                {

           conn.allowDomain( 'app#ComSender' );

           conn.client = this;

           conn.connect( 'myConnection' );

                }

       

                public function showThis( ) : void

                {

           Alert.show( "Communication worked" );

                }

      ]]>