Sample name: communication between two swf from the same domain . Author: Eriks Kruze. Developed with: FleshDevelop v3, Flex SDK 3.
Nosaukums: Divu swf (kuri atrodas tajā pašā domēnā) savstarpēja komunikācija.
Download source: localconnection.rar
-- sender.swf --
        package 
        {
            import flash.display.Sprite;
            import flash.net.LocalConnection;
            import flash.text.TextField;
            import flash.text.TextFieldType;
            import flash.events.MouseEvent;
            
            [SWF(width="200", height="100", frameRate="31")]
            
            public class sender extends Sprite
            {
                private var input: TextField;
                private var button: Sprite;
                private var button_text: TextField;
                private var conn: LocalConnection;
                
                public function sender():void
                {
                    input = new TextField();
                    input.type =  TextFieldType.INPUT;
                    input.text = 'Write here and push button';
                    input.border = true;
                    input.height = 20;
                    input.width = 190;
                    input.x = 5;
                    input.y = 5;
                    input.textColor = 0x000000;
                    addChild(input);
                    
                    button_text = new TextField();
                    button_text.text = 'Send';
                    button_text.x = 85;
                    button_text.y = 50;
                    addChild(button_text);
                    
                    button = new Sprite();
                    button.graphics.lineStyle(0.5, 0x000000, 1);
                    button.graphics.beginFill(0x000000, 0.3);
                    button.graphics.drawRect(80, 50, 40, 20);
                    button.graphics.endFill();
                    button.addEventListener(MouseEvent.CLICK, pushButton);
                    addChild(button);
                    
                    conn = new LocalConnection();
                }
                
                public function pushButton(e:MouseEvent):void
                {
                    /* to use this in situations when each swf is from different host then conection name must start with underscore: _con1 */
                    conn.send('con1', 'methodToExecute', input.text);
                    input.text = 'Sent!';
                }
            }
            
        }
        
-- receiver.swf --
        package 
        {
            import flash.display.Sprite;
            import flash.net.LocalConnection;
            import flash.text.TextField;
            import flash.text.TextFieldType;
            
            [SWF(width="200", height="100", frameRate="31")]
            
            public class receiver extends Sprite
            {
                private var value: String;
                private var output: TextField;
                private var button: Sprite;
                private var conn: LocalConnection;
                
                public function receiver():void
                {
                    output = new TextField();
                    output.type =  TextFieldType.INPUT;
                    output.text = '';
                    output.border = true;
                    output.height = 20;
                    output.width = 190;
                    output.x = 5;
                    output.y = 5;
                    output.textColor = 0x000000;
                    addChild(output);
                    
                    conn = new LocalConnection();
                    //conn.allowDomain('*'); /* to cann connect from diferent domains */
                    conn.client = this;
                    try {
                        conn.connect('con1'); /* to use this in situations when each swf is from different host then conection name must start with underscore: conn.connect('_con1'); */
                    } catch (error:ArgumentError) {
                        output.text = 'error: connection already exist! close other browsers!';
                    }
                }
                
                // function that is called by sender.swf
                public function methodToExecute(msg:String):void
                {
                    output.text = msg;
                }
            }
            
        }