1 Reply Latest reply on Jun 8, 2011 10:54 PM by seRajan

    LocalConnection Return Value

    Yue_Hong Level 1

      Hi,

       

      Is it possible to have a function in an SWF file which is connected via localconnection from flex return a value after the job is done?

       

      Example:

      On Flex:

      conn = new LocalConnection();

      protected function sendMessage():void {
           msg= conn.send("swfConnection", "swffunction", "message");

           Alert.show(msg);

      }

       

      On SWF:

      public function swffunction(msg:String):String{   

           return msg;

      }

        • 1. Re: LocalConnection Return Value
          seRajan

          hi,

           

          send method return type is void. So you are not able to get back the result via send method. If you require the responce you should you STATUS Event hander.

          This is will help you to konw the sending status, else you can add another LocalConnection Object for reciever side.

           

          Sample:

           

          File 1 :

           

           

           

          import flash.net.LocalConnection;

           

          var connection:LocalConnection = new LocalConnection();

          connection.connect("rajan");

          connection.client = this;

           

          var swfCon:LocalConnection = new LocalConnection();

           

          var count:Number = 0;

           

          function TestFun(str:String):void

          {

                    _txt.text = str;

              

                    swfCon.send("responce", "ResponceFun", str+" "+(++count));

          }

           

           

           

          File 2:

           

           

           

          import flash.net.LocalConnection;

          import flash.events.MouseEvent;

          import flash.events.StatusEvent;

           

          var connection:LocalConnection = new LocalConnection();

          connection.connect("responce");

          connection.client = this;

           

          var swfCon:LocalConnection = new LocalConnection();

          //swfCon.addEventListener(StatusEvent.STATUS, statusHandler);

           

          _btn.addEventListener(MouseEvent.CLICK, buttonHandler);

           

          var count:Number = 0;

           

          function buttonHandler(evt:MouseEvent):void

          {

                    swfCon.send("rajan", "TestFun", "Test Text"+(++count));

          }

           

          function statusHandler(evt:StatusEvent):void

          {

                    switch (evt.level) {

                              case "status":

                                      _txt.text = ("LocalConnection.send() succeeded");

                                      break;

                              case "error":

                                      _txt.text = ("LocalConnection.send() failed");

                                      break;

                         }

          }

           

          function ResponceFun(str:String):void

          {

                    _txt.text = str;

          }

           

           

           

          - Rajan