LocalConnection

LocalConnection is a simple way to send messages between two seperate swf files embedded in the same html page.

Flash has a limit of a maximum stage width of 2880 and stage height of 2880. While most projects won't require you to bust that limit, in this case we needed to stack up a few screens horizontally as the interactive had one master computer which would show the interactive across a few different screens (also, the program used to split the screen content over different screens required us to stack content horizonally rather than vertically).

The easiest solution to the width limit was to embed the seperate flash files on the same html and then have them communicate via LocalConnection.

Here is both an AS3 and AS2 version which I used for a recent project.

Sender
stop;

var sending_lc:LocalConnection; sending_lc = new LocalConnection;

function b01_1_send(evt:MouseEvent):void { sending_lc.send("locallyConnecting", "execute_this", "b01_1"); } function b01_2_send(evt:MouseEvent):void { sending_lc.send("locallyConnecting", "execute_this", "b01_2"); } function b01_3_send(evt:MouseEvent):void { sending_lc.send("locallyConnecting", "execute_this", "b01_3"); } function b02_1_send(evt:MouseEvent):void { sending_lc.send("locallyConnecting", "execute_this", "b02_1"); } function b02_2_send(evt:MouseEvent):void { sending_lc.send("locallyConnecting", "execute_this", "b02_2"); }

b01_1.addEventListener(MouseEvent.MOUSE_UP, b01_1_send); b01_2.addEventListener(MouseEvent.MOUSE_UP, b01_2_send); b01_3.addEventListener(MouseEvent.MOUSE_UP, b01_3_send); b02_1.addEventListener(MouseEvent.MOUSE_UP, b02_1_send); b02_2.addEventListener(MouseEvent.MOUSE_UP, b02_2_send); 

Receiver
 stop; var receiving_lc:LocalConnection; receiving_lc = new LocalConnection; receiving_lc.connect("locallyConnecting"); receiving_lc.client = this; function execute_this(new_text:String):void { tracetext.text = "tracing LC var: "+new_text; gotoAndPlay(new_text); }



Sender
sending_lc = new LocalConnection;

b01_1.onRelease = function { sending_lc.send("locallyConnecting", "execute_this", "b01_1"); } b01_2.onRelease = function { sending_lc.send("locallyConnecting", "execute_this", "b01_2"); } b01_3.onRelease = function { sending_lc.send("locallyConnecting", "execute_this", "b01_3"); } b02_1.onRelease = function { sending_lc.send("locallyConnecting", "execute_this", "b02_1"); } b02_2.onRelease = function { sending_lc.send("locallyConnecting", "execute_this", "b02_2"); }

Receiver
stop;

receiving_lc = new LocalConnection; receiving_lc.execute_this = function(new_text) { tracetext.text = "tracing LC var: "+new_text; gotoAndPlay(new_text); } receiving_lc.connect("locallyConnecting"); 