Ignoring crossdomain.xml policy with AS3
February 8th, 2008In AS2, when you wanted to load in an external file (i.e. .jpg) from a remote server that did not have a crossdomain.xml file allowing you to communicate with the server, you could easily override this with the MovieClipLoader class. As long as you did not try to alter the image with the Bitmap object, you were in good shape for the most part.
With MovieClipLoader depreciated in AS3, you can still override the absense of crossdomain.xml utilized on the remote server when loading in images. However, the way to do it is a little trickier. Observe:
package {
import flash.display.*;
import flash.events.Event;
import flash.net.*;
import flash.system.LoaderContext;public class FeaturedProduct extends Sprite {
public var imgLoader:Loader;
public var context:LoaderContext;public function FeaturedProduct(){
buildImage();
}private function buildImage():void {
context = new LoaderContext();
context.checkPolicyFile = false;imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);
var urlRequest:URLRequest = new URLRequest(”http://www.someremoteurl.com/images/sampleimg.jpg”);
imgLoader.load(urlRequest,context);
}private function completeListener(e:Event):void {
this.addChild(imgLoader);
}
}
}
In particular, look at the LoaderContext() usage. Without going too much into detail, you can read much more thorough documentation on this at Adobe


