3 Replies Latest reply on Oct 22, 2008 9:56 AM by Athang

    local connection

    phil1943 Level 1
      Hello, I am trying to use local connection to make an AS2 SWF call a Flex SWF.
      The AS2 SWF will send data to the receiveData function within the Flex SWF, which will in turn display the received data in a textArea component named "myTextArea. However, it does not work. Can anyone see any obvious errors ? Thanks kindly in advance.

      My relevant code in the AS2 SWF is:
      var senderLC:LocalConnection = new LocalConnection();
      senderLC.send( "fromFlash", "receiveData", "dataToSend" );

      My relevant code in the Flex SWF is:
      import flash.net.LocalConnection;
      var receiverLC:LocalConnection = new LocalConnection();
      receiverLC.connect("fromFlash");
      receiverLC.client = this;

      function receiveData(incomingData:String):void {
      myTextArea.text = incomingData;
      }
        • 1. Re: local connection
          Athang
          Hello,
          I have made some changes in code, please check this code is working or not?

          var senderLC:LocalConnection = new LocalConnection();
          senderLC.send( "fromFlash", "receiveData", "dataToSend" );
          // Add the following code to check the connection status
          senderLC.onStatus = function (info:Object)
          {
          switch (info.level)
          {
          case 'status':
          trace("Local connection is succecced.");
          break;
          case 'error':
          trace ("Local connection fail to connect.");
          break;
          }
          }

          Also please check you connection string in send method that is "fromFlash" is correct.
          I think it has to be like -
          senderLC.send( "app#FlexFileName:fromFlash", "receiveData", "dataToSend" );

          //////////////////////////////////
          Flex Code -
          import flash.net.LocalConnection;
          var receiverLC:LocalConnection = new LocalConnection();
          receiverLC.allowDomain();
          receiverLC.client = this;
          receiverLC.connect("fromFlash");


          function receiveData(incomingData:String):void {
          myTextArea.text = incomingData;
          }


          • 2. local connection
            phil1943 Level 1
            Thanks for your help. I tried but still no luck. I ran the onStatus procedure and established no connection was taking place.
            Here is another summary of what I am doing.

            My AS2 SWF is embedded into a Flex 3 parent SWF via SWFLoader. I want the AS2 SWF to connect with the parent Flex 3 SWF and pass a variable. Are there any know issues ? I cant get mine to work.
            Here is my AS2 SWF code:

            var senderLC = new LocalConnection();
            senderLC.send("fromFlash", "receiveData", selections );

            It is calling the function "receiveData" within the parent Flex 3 SWF and sending a string variable called selections.
            Here is my Flex 3 receiver SWF code.

            <mx:Script>
            <![CDATA[
            public function initApp() : void {
            import flash.net.LocalConnection;
            var receiverLC:LocalConnection = new LocalConnection();
            receiverLC.client = this;
            receiverLC.connect("fromFlash");
            }
            public function receiveData(incomingData:String):void {
            myTextArea.text = incomingData
            }
            ]]>
            </mx:Script
            • 3. Re: local connection
              Athang Level 1
              Hello,

              I have added one line of code in Flex file and reorder the statements, please check this.

              import flash.net.LocalConnection;
              var receiverLC:LocalConnection = new LocalConnection();
              receiverLC.allowDomain();
              receiverLC.client = this;
              receiverLC.connect("fromFlash");

              function receiveData(incomingData:String):void {
              myTextArea.text = incomingData;
              }


              I have also get link where, how to make a two way local connection is explained.
              http://prashantbhagwat.wordpress.com/2008/08/13/air_swf-communication/
              LocalConnection