I have a Flex swf hosted at I have a flash code on another doamin that tries loading the SWF:

_loader = new Loader(); var req:URLRequest = new URLRequest(""); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaderFinish); _loader.load(req);

On the onLoaderFinish event I try to load classes from the remote SWF and create them: _loader.contentLoaderInfo.applicationDomain.getDefinition("someClassName") as Class

When this code runs I get the following exception SecurityError: Error #2119: Security sandbox violation: caller http://localhost.service:1234/flashTest/Main.swf cannot access LoaderInfo.applicationDomain owned by at flash.display::LoaderInfo/get applicationDomain() at NuconomyLoader/onLoaderFinish()

Is there any way to get this code working?


Mayhaps System.Security.allowDomain is what you need?

+5  A: 

This is all described in The Adobe Flex 3 Programming ActionScript 3 PDF on page 550 (Chapter 27: Flash Player Security / Cross-scripting):

If two SWF files written with ActionScript 3.0 are served from different domains—for example, and—then, by default, Flash Player does not allow swfA.swf to script swfB.swf, nor swfB.swf to script swfA.swf. A SWF file gives permission to SWF files from other domains by calling Security.allowDomain(). By calling Security.allowDomain(""), swfB.swf gives SWF files from permission to script it.

It goes on in some more detail, with diagrams and all.

+2  A: 

You'll need a crossdomain.xml policy file on the server that has the file you load, it should look a something like this:

<?xml version="1.0"?>
<!-- <; -->
  <allow-access-from domain="" />
  <allow-access-from domain="*" />
  <allow-access-from domain="" />

Put it as crossdomain.xml in the root of the domain you're loading from.

Also you need to set the loader to read this file as such:

var loaderContext:LoaderContext = new LoaderContext();
loaderContext.checkPolicyFile = true;

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete );
loader.load( new URLRequest( "" ), loaderContext );

code sample yoinked from