Flash Player 6.
The LocalConnection class lets you develop SWF files that can send instructions to each other without the use of fscommand() or JavaScript. LocalConnection objects can communicate only among SWF files that are running on the same client computer, but they can be running in different applications--for example, a SWF file running in a browser and a SWF file running in a projector. You can use LocalConnection objects to send and receive data within a single SWF file, but this is not a standard implementation; all the examples in this section illustrate communication between different SWF files.
The primary methods used to send and receive data are LocalConnection.send() and LocalConnection.connect(). At its most basic, your code will implement the following commands; notice that both the LocalConnection.send() and LocalConnection.connect() commands specify the same connection name, lc_name:
// Code in the receiving SWF file
this.createTextField("result_txt", 1, 10, 10, 100, 22);
result_txt.border = true;
var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.methodToExecute = function(param1:Number, param2:Number) {
result_txt.text = param1+param2;
};
receiving_lc.connect("lc_name");
// Code in the sending SWF file
var sending_lc:LocalConnection = new LocalConnection();
sending_lc.send("lc_name", "methodToExecute", 5, 7);
The simplest way to use a LocalConnection object is to allow communication only between LocalConnection objects located in the same domain because you won't have security issues. However, if you need to allow communication between domains, you have several ways to implement security measures. For more information, see the discussion of the connectionName parameter in LocalConnection.send() and the LocalConnection.allowDomain and LocalConnection.domain() entries.
| Method | Description |
|---|---|
|
Closes (disconnects) the LocalConnection object. |
|
Prepares the LocalConnection object to receive commands from a |
|
Returns a string representing the superdomain of the location of the current SWF file. |
|
Invokes a method on a specified LocalConnection object. |
| Event handler | Description |
|---|---|
LocalConnection.allowDomain |
Invoked whenever the current (receiving) LocalConnection object receives a request to invoke a method from a sending LocalConnection object. |
LocalConnection.allowInsecureDomain |
Invoked whenever the current (receiving) LocalConnection object, which is in a SWF file hosted at a domain using a secure protocol (HTTPS), receives a request to invoke a method from a sending LocalConnection object that is in a SWF file hosted at a non-secure protocol. |
LocalConnection.onStatus |
Invoked after a sending LocalConnection object tries to send a command to a receiving LocalConnection object. |
Flash Player 6.
new LocalConnection() : LocalConnection
None.
A reference to a LocalConnection object.
Constructor; creates a LocalConnection object.
The following example shows how receiving and sending SWF files create LocalConnnection objects. The two SWF files can use the same name or different names for their respective LocalConnection objects. In this example they use different names.
// Code in the receiving SWF file
this.createTextField("result_txt", 1, 10, 10, 100, 22);
result_txt.border = true;
var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.methodToExecute = function(param1:Number, param2:Number) {
result_txt.text = param1+param2;
};
receiving_lc.connect("lc_name");
The following SWF file sends the request to the first SWF file.
// Code in the sending SWF file
var sending_lc:LocalConnection = new LocalConnection();
sending_lc.send("lc_name", "methodToExecute", 5, 7);
LocalConnection.connect(), LocalConnection.send()
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001421.html
Comments
recoveredfromflashMX2004 said on Aug 4, 2004 at 3:10 PM : dvhh said on Nov 10, 2004 at 2:45 PM : Paul Terhaar said on Feb 18, 2005 at 12:51 PM : No screen name said on Apr 19, 2005 at 8:34 AM : No screen name said on Jun 7, 2005 at 9:26 AM : nunomira said on Jul 27, 2005 at 4:16 PM : bobsmo said on Oct 6, 2005 at 9:09 AM : xzone9 productions said on Sep 6, 2008 at 9:11 AM : xzone9 productions said on Sep 6, 2008 at 9:20 AM : xzone9 productions said on Oct 19, 2008 at 4:43 PM :