Wednesday, April 14, 2010

crossdomain




Flash and crossdomain.xml.

What I wanted to do was to have my main Flash app load most of it's resources from one host, and then get the big media files from another host. This was almost easy, but a few things were tricky:

1) Make sure you're letting the right hosts through with your crossdomain.xml. The following file lets EVERYTHING through, which is probably not what you want:


<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>


2) Put this file in the root directory of the system that you are getting images from. I thought this needed to go on the system that the Flash was being served from, which was my big stumbling block

3) Setup a LoaderContext that will allow you to access the content as data


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


4) Use ths LoaderContext when getting the resource:


_images[zoom_level][index].load(new URLRequest(url),loader_context);