Friday, 13 March 2009

Cross Domain Image load in AS3

About Cross Domain and the Policy File:
Flash player by default prevents loading data from cross-domain servers(i.e. the swf can load the data only from the server in which it is hosted by default). However this can be over come by placing a cross domain(crossdomain.xml) policy file in the root of the different server from which the data(content) is present. The xml file will allow other domains to load the content from it. The crossdomain.xml should be in the root directory.

In flash player 9 just placing the crossdomain.xml in the servers root folder will not be enough to load the image. You must instantiate a LoaderContext object and use it along with the loader.load(urlReqst,loaderContext) function to load the image from a different domain successfully.

function loadImage(imURL:String) {
var crsDomainLoader:LoaderContext;
crsDomainLoader= new LoaderContext();
var imgLoader:Loader=new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.INIT,imgLoaded,false, 0,true);
imgLoader.load(new URLRequest(imURL),crsDomainLoader);

This is the best solution I have found and it will work finely provided the crossdoamin.xml is placed on the proper location.

Search Tags:
Cross domain image not loading
Image not loading in AS3
Image not loaded from different server
crossdomain AS3 Bug solution

No comments:

Post a Comment