- A LocalConnection object is used to invoke a method in another LocalConnection object, either within a single SWF file or between multiple SWF files.
- ActionScript 3.0 can communicate with LocalConnection objects created in ActionScript 1.0 or 2.0 and the reverse is true. Flash * Player handles this communication between LocalConnection objects of different versions automatically.
- You can use LocalConnection objects to send and receive data within a single SWF file, but this is not a typical implementation
- The sending SWF:
- contains the method to be invoked
- must contain a LocalConnection object
- a call to the send() method passing the connectionName, methodName and arguments
- The receiving SWF
- invokes the method in the sending
- must contain another LocalConnection object
- a call to the connect() method passing the connectionName argument
- Same domain connections are the easiest because Flash Player allows same-domain communication by default.
- Use the allowDomain() method on the receiving SWF to allow communication between different domains with predictable domain names.
- To avoid specifying the domain name in the send() method, but to indicate to Flash Player that the receiving and sending LocalConnection objects are not in the same domain, precede the connection name with an underscore (_), in both the connect() and send() calls.
Example code: Two Flex 3 Applications Communicating over a LocalConnection
Below are two completely separate Flex applications, each runs in its own "space". They both use the LocalConnection class one sending a task to the other. The sending application uses the send() method of the LocalConnection class to send the task. It also registers an event handler function to receive status messages as to the success or failure of the send.
The Receiver application uses the connect() method of the LocalConnection class to "sign up" and then handles actual messages as they are sent.
Rendered Example TaskSender
Rendered Example BasicTaskReceiver