1

I'm trying to create a screensaver for one our of our display we have at work. Images will be uploaded to an external server, from that server I will have pull the images and xml file. so my flash app and my content will be in two different places. I'm getting an error "SecurityError: Error #2000: No active security context". how do I override error and get the images to my stage.

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML;
var imageList:XMLList;
var imageLoader:Loader = new Loader();
var timer:Timer =new Timer(5000);
var imageIndex:uint = 0;
var child:DisplayObject;

var path:String="http://bgxserv03.mgmmirage.org/interactivemedia/mmhub01/test/mb/edit_bay/hr/infoscreen/servamb/";

xmlLoader.load(new URLRequest(path +"output.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
timer.addEventListener(TimerEvent.TIMER, tick);

function xmlLoaded(e:Event) {
     xmlData = new XML ( e.target.data);
     imageList = xmlData.image.name;
     timer.start();
     loadImage(imageList[0]);
}
 function imageLoaded(e:Event){
   if (child){
  myImageHolder.removeChild(child);
    }
 child = myImageHolder.addChild(imageLoader);
 Tweener.addTween(child, {alpha:0, time:1, delay:4});
 Tweener.addTween(child, {alpha:1, time:1, delay:5});
}

function loadImage(path:String){
imageLoader.load(new URLRequest( path +"photos/"));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);

}

Any help would be deeply appreciate. Thank you.

  • 1
    Does the error only occur locally? [This post](http://stackoverflow.com/questions/9004594/securityerror-error-2000-no-active-security-context-while-importing-external) may come in handy. – Goose Nov 05 '12 at 23:57

2 Answers2

0

You need to put the "Crossdomain.XML" on the server's root directory. This will allow your flash file to access the data (image in your case) from that server. You can get a sample xml from the following URL, customize it for your server: Sample CrossDomain.XML

Gaurav
  • 1,214
  • 2
  • 17
  • 32
0

What you are missing is probably a crossdomain.xml policy file at the domain of your image/xml files.

Use this link to create a crossdomain.xml file and add it to the root of your image/xml domain like so : "http://bgxserv03.mgmmirage.org/crossdomain.xml"

The URLLoader load() function automatically checks for the crossdomain.xml. Loader class requires you specify that you are interested in checking for a policy file in a LoaderContext object sent to the load() function.

In your code, it looks like the error should be coming from the URLLoader xml file request, since it doesn't look like you are trying to access the bitmap data of your images in any way, which is normally what would throw a security error for image files. If it is a problem with the image loading part, then complete the following instructions and you should be set to go:

In your loadImage function, add a LoaderContext parameter to your load method call:

function loadImage(path:String){
    var loaderContext:LoaderContext = new LoaderContext();
    loaderContext.checkPolicyFile = true;
    imageLoader.load(new URLRequest( path +"photos/"), loaderContext);
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);
}

Check out the spec for more info on how to use the Loader class.

If you run into any trouble, this thread may be helpful.

Community
  • 1
  • 1
Amit Dvir
  • 337
  • 1
  • 3
  • 9