View comments | RSS feed

LocalConnection


Object
    |
    +-LocalConnection

public dynamic class LocalConnection
extends Object

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.

Availability: ActionScript 1.0; Flash Player 6

Property summary

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

allowDomain = function([sendingDomain:String]) {}

Invoked whenever receiving_lc receives a request to invoke a method from a sending LocalConnection object.

allowInsecureDomain = function([sendingDomain:String]) {}

Invoked whenever receiving_lc, 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 nonsecure protocol.

onStatus = function(infoObject:Object) {}

Invoked after a sending LocalConnection object tries to send a command to a receiving LocalConnection object.

Constructor summary

Signature

Description

LocalConnection()

Creates a LocalConnection object.

Method summary

Modifiers

Signature

Description

 

close() : Void

Closes (disconnects) a LocalConnection object.

 

connect(connectionName:String) : Boolean

Prepares a LocalConnection object to receive commands from a LocalConnection.send() command (called the sending LocalConnection object).

 

domain() : String

Returns a string representing the domain of the location of the current SWF file.

 

send(connectionName:String, methodName:String, [args:Object]) : Boolean

Invokes the method named method on a connection opened with the LocalConnection.connect(connectionName) command (the receiving LocalConnection object).

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


ion gion said on Jul 5, 2007 at 4:41 AM :
Working with LocalConnection i have discovered that there are limitations regarding of what kind of objects can be sent as parameters to remote functions. I cannot send a MovieClip or a NetConnection instantiated, connected object.

This is terrible, at least NetConnection should be allowed to be sent.

What types of objects can be sent over LocalConnection send method ?
Are only primitive types supported ?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002338.html