328
Chapter 6: ActionScript Core Classes
LocalConnection class
Availability
Flash Player 6.
Description
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. (A projector is a SWF file saved in a format that can run as a stand-alone application—
that is, without Flash Player.) 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 = 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 summary for the LocalConnection class
Method
Description
LocalConnection.close()
Closes (disconnects) the LocalConnection object.
LocalConnection.connect()
Prepares the LocalConnection object to receive
commands from a
LocalConnection.send()
command.
CHAPTER 6
ActionScript Core Classes
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...