Example
The following example shows how a SWF file in a particular domain can invoke a method named
in a receiving SWF file in the same domain. The receiving SWF file functions as a trace
Trace
window for the sending SWF file; it contains two methods that other SWF files can call—
and
Trace
Clear
specified parameters.
// Receiving SWF
var aLocalConnection = new LocalConnection();
aLocalConnection.Trace = function(aString)
{
aTextField = aTextField + aString + newline;
}
aLocalConnection.Clear = function()
{
aTextField = "";
}
aLocalConnection.connect("trace");
stop();
SWF 1 contains the following code attached to a button labeled PushMe. When you push the
button, you see the sentence "The button was pushed." in the receiving SWF file.
on (press)
{
var lc = new LocalConnection();
lc.send("trace", "Trace", "The button was pushed.");
delete lc;
}
SWF 2 contains an input text box with a var name of
a button labeled Copy. When you type some text and then push the button, you see the text you
typed in the receiving SWF file.
on (press)
{
_parent.lc.send("trace", "Trace", _parent.myText);
_parent.myText = "";
}
SWF 3 contains the following code attached to a button labeled Clear. When you push the
button, the contents of the trace window in the receiving SWF file are cleared (erased).
on (press)
{
var lc = new LocalConnection();
lc.send("trace", "Clear");
delete lc;
}
See also
LocalConnection.send()
440
Chapter 12: ActionScript Dictionary
. Buttons pressed in the sending SWF files call these methods with
, and the following code attached to
myText
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers