The following example sends a string to the previous SWF file and displays a status message about
whether the local connection was able to connect to the file. A TextInput component called
, a TextArea instance called
name_ti
used to display content.
var sending_lc:LocalConnection;
var sendListener:Object = new Object();
sendListener.click = function(evt:Object) {
sending_lc = new LocalConnection();
sending_lc.onStatus = function(infoObject:Object) {
switch (infoObject.level) {
case 'status' :
status_ta.text = "LocalConnection connected successfully.";
break;
case 'error' :
status_ta.text = "LocalConnection encountered an error.";
break;
}
};
sending_lc.send("_mylc", "sayHello", name_ti.text);
};
send_button.addEventListener("click", sendListener);
In the following example, the receiving SWF file, which resides in thisDomain.com, accepts
commands only from SWF files located in thisDomain.com or thatDomain.com:
var aLocalConn:LocalConnection = new LocalConnection();
aLocalConn.Trace = function(aString) {
aTextField += aString+newline;
};
aLocalConn.allowDomain = function(sendingDomain) {
return (sendingDomain == this.domain() || sendingDomain ==
"www.macromedia.com");
};
aLocalConn.connect("_mylc");
When published for Flash Player 7 or later, exact domain matching is used. This means that the
example will fail if the SWF files are located at www.thatDomain.com but will work if the files are
located at thatDomain.com.
See also
LocalConnection.connect(), LocalConnection.domain(), LocalConnection.send(),
MovieClip._url, MovieClipLoader.onLoadComplete,
and a Button instance called
status_ta
send_button
_parent
LocalConnection.allowDomain
are
405
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers