1

我正在尝试为我们工作中的显示器创建一个屏幕保护程序。图像将上传到外部服务器,我将从该服务器中提取图像和 xml 文件。所以我的 Flash 应用程序和我的内容将位于两个不同的地方。我收到一个错误“SecurityError: Error #2000: No active security context”。如何覆盖错误并将图像带到我的舞台。

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);

}

任何帮助将不胜感激。谢谢你。

4

2 回答 2

0

您需要将“Crossdomain.XML”放在服务器的根目录中。这将允许您的闪存文件从该服务器访问数据(在您的情况下为图像)。您可以从以下 URL 获取示例 xml,为您的服务器自定义它: 示例 CrossDomain.XML

于 2012-11-06T08:06:02.567 回答
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.

于 2012-11-06T08:09:27.970 回答