Recipe 15.2 Loading an External SWF from a Trusting Domain

15.2.1 Problem

You want to load an external .swf file into your Flash movie, but the .swf file resides within a different domain.

15.2.2 Solution

Use the allowDomain( ) method from within the .swf file you want to load to create a trusting relationship between the domains.

15.2.3 Discussion

The System.security.allowDomain( ) method allows you to create trusting relationships between .swf files in different domains. The allowDomain( ) method must be called from within the .swf file you wish to load. Therefore, this technique is applicable only if you want to load .swf files to which you can add the allowDomain( ) method call. Otherwise, see Recipe 15.6 to load content by a proxy script.

Here is a scenario in which you can use allowDomain( ) to create a trusting relationship: you have two .swf files, my.swf and your.swf. The my.swf movie is on www.mydomain.com, and your.swf is on www.yourdomain.com. If you want my.swf to be able to load your.swf, add the following line to your.swf:

System.security.allowDomain("mydomain.com");

This line of code tells your.swf to allow itself to be loaded by any movies in the mydomain.com domain. The my.swf movie can then load your.swf using a standard loadMovie( ) method call:

// Create myMovieClip using createEmptyMovieClip(  ). _root.createEmptyMovieClip("myMovieClip", 1); // Load the trusting .swf file into myMovieClip. myMovieClip.loadMovie("http://www.yourdomain.com/your.swf");

If you want to allow your.swf to be loaded from more than one domain, you can specify them as a series of parameters passed to the allowDomain( ) method. For example:

System.security.allowDomain("mydomain.com", "anotherdomain.org", "yetanother.net");

The parameters of the allowDomain( ) method can be in any of the following formats:

"mydomain.com" "http://mydomain.com" "http://ipaddress"

15.2.4 See Also

Recipe 15.6 and Recipe 17.4



ActionScript Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2005
Pages: 425

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net