LocalConnection.allowDomain
331
In files authored for Flash Player 6, the
sendingDomain
parameter contains the superdomain of
the caller. In files authored for Flash Player 7 or later, the
sendingDomain
parameter contains the
exact domain of the caller. In the latter case, to allow access by SWF files hosted at either
www.domain.com or store.domain.com, you must explicitly allow access from both domains.
// For Flash Player 6
receiving_lc
.allowDomain = function(sendingDomain) {
return(sendingDomain=="domain.com");
}
// For Flash Player 7 or later
receiving_lc
.allowDomain = function(sendingDomain) {
return(sendingDomain=="www.domain.com" ||
sendingDomain=="store.domain.com");
}
Also, for files authored for Flash Player 7 or later, you can’t use this method to let SWF files
hosted using a secure protocol (HTTPS) allow access from SWF files hosted in nonsecure
protocols; you must use the
LocalConnection.allowInsecureDomain
event handler instead.
Occasionally, you might encounter the following situation. Suppose you load a child SWF file
from a different domain. You want to implement this method so that the child SWF file can
make LocalConnection calls to the parent SWF file, but you don’t know the final domain from
which the child SWF file will come. This can happen, for example, when you use load-balancing
redirects or third-party servers.
In this situation, you can use the
MovieClip._url
property in your implementation of this
method. For example, if you load a SWF file into
my_mc
, you can then implement this method by
checking whether the domain argument matches the domain of
my_mc._url
. (You must parse the
domain out of the full URL contained in
my_mc._url
.)
If you do this, make sure that you wait until the SWF file in
my_mc
is loaded, because the
_url
property will not have its final, correct value until the file is completely loaded. The best way to
determine when a child SWF file finishes loading is to use
MovieClipLoader.onLoadComplete
.
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.
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) {
Содержание FLEX
Страница 1: ...Flex ActionScript Language Reference ...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Страница 135: ...case 135 See also break default strict equality switch ...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in ...
Страница 808: ...808 Chapter 7 ActionScript for Flash ...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators ...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Страница 822: ...822 Index ...