User Guide
336 Chapter 6: ActionScript Core Classes
If you are implementing communication between SWF files in different domains, specifying a
string for
connectionName that begins with an underscore (_) will make the SWF with the
receiving LocalConnection object more portable between domains. Here are the two possible
cases:
• If the string for connectionName does not begin with an underscore (_), Flash Player adds a
prefix with the superdomain and a colon (for example,
"myDomain:connectionName").
Although this ensures that your connection does not conflict with connections of the same
name from other domains, any sending LocalConnection objects must specify this
superdomain (for example,
"myDomain:connectionName"). If the SWF with the receiving
LocalConnection object is moved to another domain, the player changes the prefix to reflect
the new superdomain (for example,
"anotherDomain:connectionName"). All sending
LocalConnection objects would have to be manually edited to point to the new superdomain.
• If the string for connectionName begins with an underscore (for example,
"_connectionName"), Flash Player does not add a prefix to the string. This means that the
receiving and sending LocalConnection objects will use identical strings for
connectionName.
If the receiving object uses
LocalConnection.allowDomain to specify that connections from
any domain will be accepted, the SWF with the receiving LocalConnection object can be
moved to another domain without altering any sending LocalConnection objects.
For more information, see the discussion of
connectionName in LocalConnection.send() and
also the
LocalConnection.allowDomain and LocalConnection.domain() entries.
Note: Colons are used as special characters to separate the superdomain from the connectionName
string. A string for connectionName that contains a colon is not valid.
Example
The following example shows how a SWF file in a particular domain can invoke a method named
Trace in a receiving SWF file in the same domain. The receiving SWF file functions as a trace
window for the sending SWF file; it contains two methods that other SWF files can call—
Trace and Clear. Buttons pressed in the sending SWF files call these methods with
specified parameters.
// Receiving SWF
var aLocalConnection:LocalConnection = new LocalConnection();
aLocalConnection.Trace = function(aString):String{
aTextField += aString + newline;
}
aLocalConnection.Clear = function(){
aTextField = "";
}
aLocalConnection.connect("trace");
stop();
SWF 1 contains the following code, which creates a new Sound object that plays back an MP3
file at runtime. A ProgressBar called
playback_pb displays the playback progress of the MP3 file.
A Label component instance called
song_lbl displays the name of the MP3 file. Buttons in
different SWF files will be used to control the playback using a LocalConnection object.
var playback_pb:mx.controls.ProgressBar;
var my_sound:Sound;