LocalConnection
715
The opposite situation can also occur: You might create a child SWF file that wants to accept
LocalConnection calls from its parent but doesn't know the domain of its parent. In this
situation, implement this method by checking whether the domain argument matches the
domain of _parent._url. Again, you must parse the domain out of the full URL from
_parent._url. In this situation, you don't have to wait for the parent SWF file to load; the
parent will already be loaded by the time the child loads.
Availability:
ActionScript 1.0; Flash Player 7
Parameters
sendingDomain
:String
[optional] - A string that specifies the domain of the SWF file that
contains the sending LocalConnection object.
Example
The following example shows how a LocalConnection object in a receiving SWF file can
permit SWF files from any domain to invoke its methods. Compare this to the example in
LocalConnection.connect()
, in which only SWF files from the same domain can invoke
the
trace()
method in the receiving SWF file. For a discussion of the use of the underscore
(_) in the connection name, see
LocalConnection.send()
.
this.createTextField("welcome_txt", this.getNextHighestDepth(), 10, 10,
100, 20);
var my_lc:LocalConnection = new LocalConnection();
my_lc.allowDomain = function(sendingDomain:String) {
domain_txt.text = sendingDomain;
return true;
};
my_lc.allowInsecureDomain = function(sendingDomain:String) {
return (sendingDomain == this.domain());
}
my_lc.sayHello = function(name:String) {
welcome_txt.text = "Hello, "+name;
};
my_lc.connect("_mylc");
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
name_ti
, a TextArea instance called
status_ta
and a Button instance called
send_button
are 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) {
Содержание FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Страница 1: ...ActionScript 2 0 Language Reference ...
Страница 1352: ...1352 ActionScript classes ...