views:

2217

answers:

2

I'm trying to load Gravatars into Flash. Luckily, they provided a crossdomain.xml file at http://en.gravatar.com/avatar/crossdomain.xml

My code:

Security.loadPolicyFile("http://en.gravatar.com/avatar/crossdomain.xml");
var loader:Loader = new Loader();
loader.load(new URLRequest("http://en.gravatar.com/avatar/" + gravatar + "?s=35&d=identicon"));

But I'm still getting this error:

SecurityError: Error #2123: Security sandbox violation: LoaderInfo.content: [...] cannot access http://en.gravatar.com/avatar/97fbce86a5bbc520450168603172cd9e?s=35&d=identicon. No policy files granted access.
at flash.display::LoaderInfo/get content()
at PiecePlayerSmall/onLoadComplete()

I also monitored the traffic the Flash file is sending. It's requesting:

Any suggestions for getting this to work and reducing the number of requests to gravatar.com.

EDIT: The following code works, thanks to Jacob

Security.loadPolicyFile("http://en.gravatar.com/avatar/crossdomain.xml");
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.applicationDomain = ApplicationDomain.currentDomain;
var request:URLRequest = new URLRequest(
    "http://en.gravatar.com/avatar/" + gravatar + "?s=35&d=identicon");
var loader:Loader = new Loader();
loader.load(request, context);
this.addChild(loader);

Note: Do not try to access the content directly in the Event.COMPLETE

+3  A: 

I got around a similar issue by using a LoaderContext. Here's an example of how to do this:

var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
var request:URLRequest = new URLRequest(
    "http://en.gravatar.com/avatar/" + gravatar + "?s=35&d=identicon");
var loader:Loader = new Loader();
loader.load(request, context);
Jacob
St. John Johnson
Okay, this solved my problem! Don't add the SecurityDomain though, it only makes things worse. Also, you cannot directly access the content of the Loader, that throws another error.
St. John Johnson
A: 

Thx, it helped a lot

Dawe