10 Replies Latest reply on Sep 13, 2010 6:28 PM by Yue_Hong

    LocalConnection in Flex 4

    Yue_Hong Level 1

      Hi,

       

      Is there any example or tutorial on LocalConnection in Flex 4? I have done online searching but can't find one example that works on Flex 4. Thanks.

        • 1. Re: LocalConnection in Flex 4
          Flex harUI Adobe Employee

          If it works in Flex 3, it should work the same in Flex 4.

          • 2. Re: LocalConnection in Flex 4
            Yue_Hong Level 1

            Thanks for your reply. I have tried but Flex shows error message.

             

            import mx.events.FlexEvent;
            private var conn:LocalConnection;
                           protected function initConn():void{
                                conn = new LocalConnection();
                           }
                           
                           protected function sendMessage():void {
                                conn.send("taskConnection", "localconnectionHandler", "wahahhaahahaah");
                           }
            
            

             

            The error:

            1061: Call to a possibly undefined method send through a reference with static type LocalConnection.

            • 3. Re: LocalConnection in Flex 4
              Flex harUI Adobe Employee

              Is that in an MXML script block?  If it is in AS file, then you may just

              need to

                  import flash.net.LocalConnection;

              • 4. Re: LocalConnection in Flex 4
                Yue_Hong Level 1

                I have just added in import flash.net.LocalConnection; into <fx:Script> tag. But the same error is still appear.

                • 5. Re: LocalConnection in Flex 4
                  Flex harUI Adobe Employee

                  It compiles just fine for me even without the import.  Try a new simple test

                  project and see what happens.

                  • 6. Re: LocalConnection in Flex 4
                    Yue_Hong Level 1

                    I have tried to copy and paste into new one, but it appears to be more errors.

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                                                xmlns:s="library://ns.adobe.com/flex/spark"
                                                xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="initConn()">
                         <fx:Script>
                              <![CDATA[
                                   import mx.events.FlexEvent;
                                   private var conn:LocalConnection;
                                   protected function initConn():void{
                                        conn = new LocalConnection();
                                   }
                                   
                                   protected function sendMessage():void {
                                        conn.send("taskConnection", "localconnectionHandler", "wahahhaahahaah");
                                   }

                              ]]>
                         </fx:Script>
                         <fx:Declarations>
                              <!-- Place non-visual elements (e.g., services, value objects) here -->
                         </fx:Declarations>
                    </s:WindowedApplication>

                     

                    The errors are:

                    1046:Type was not found or was not a compile-time constant:LocalConnection.
                    1180: Call to a possibly undefined method LocalConnection.

                     

                    Why is the errors appear? How can I solve the problem? Thanks.

                    • 7. Re: LocalConnection in Flex 4
                      Flex harUI Adobe Employee

                      Dunno, try it in a non-AIR application.

                      • 8. Re: LocalConnection in Flex 4
                        Yue_Hong Level 1

                        yeah, I have just try on non-air application and it seems to be working fine.... So, how can I fix it to have it work on air application? Thanks.

                        • 9. Re: LocalConnection in Flex 4
                          Flex harUI Adobe Employee

                          An AIR app worked for me.  Is your AIR project just one file?  Maybe you

                          have another class or variable named LocalConnection?

                          • 10. Re: LocalConnection in Flex 4
                            Yue_Hong Level 1

                            Thanks a lot for your help. I just found that my experiment file name is LocalConnection. After changing the name, the problem solves.