SecurityError:错误#2122:安全沙箱违规:LoaderInfo.content:
我正在创建一个使用平铺和 xml 文件的游戏。我正在尝试从外部服务器检索这些文件。当我在本地计算机上以调试模式运行该程序时,它运行得很好。但是当我上传到服务器时。我收到此错误
SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content:
A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
下面是我的代码
private function init():void
{
game = new EngineApi();
gameObject.eApi = game;
gameObject.EG = this;
game.Tiling(true,800,640,80,80);
game.tileEg.offsY = 7000;
game.tileEg.ScrollLoop(true,0,1,true);//0,1
context.checkPolicyFile = true;
flash.system.Security.loadPolicyFile("http://mysite.com/images/tileSheet.png");
flash.system.Security.loadPolicyFile("http://mysite.com/images/world.xml");//map 0
flash.system.Security.loadPolicyFile("http://mysite.com/images/world1.xml");//map 1
flash.system.Security.loadPolicyFile("http://mysite.com/images/world7.xml");//world 7 and 8 are train track maps. map 2
flash.system.Security.loadPolicyFile("http://mysite.com/images/world8.xml");//map 3
flash.system.Security.loadPolicyFile("http://mysite.com/images/world9.xml");//Ending of 8 //map 4
flash.system.Security.loadPolicyFile("http://mysite.com/images/world10spaceInvader.xml");//Beginning of tracks being centered //map 5
flash.system.Security.loadPolicyFile("http://mysite.com/images/world11LoopBoss.xml");//Tracks loop (you fight boss) //map 6
flash.system.Security.loadPolicyFile("http://mysite.com/images/world12toDesert.xml");//map 7
flash.system.Security.loadPolicyFile("http://mysite.com/images/world2.xml");//map 8
flash.system.Security.loadPolicyFile("http://mysite.com/images/world3.xml");//map 9
flash.system.Security.loadPolicyFile("http://mysite.com/images/world13DesertDoubleTrain.xml");//map 10
flash.system.Security.loadPolicyFile("http://mysite.com/images/world14DoubleTrain.xml");//map 11
game.AddTileSheet("http://mysite.com/images/tileSheet.png");
game.tw = 80;
game.th = 80;
game.LoadTileSheets();
game.addEventListener("tileLoadComplete", prePareTiles);
//anything labeled with map (i.e. map 1) is the order of how the game see's it
game.addXml("http://mysite.com/images/world.xml");//map 0
game.addXml("http://mysite.com/images/world1.xml");//map 1
game.addXml("http://mysite.com/images/world7.xml");//world 7 and 8 are train track maps. map 2
game.addXml("http://mysite.com/images/world8.xml");//map 3
game.addXml("http://mysite.com/images/world9.xml");//Ending of 8 //map 4
game.addXml("http://mysite.com/images/world10spaceInvader.xml");//Beginning of tracks being centered //map 5
game.addXml("http://mysite.com/images/world11LoopBoss.xml");//Tracks loop (you fight boss) //map 6
game.addXml("http://mysite.com/images/world12toDesert.xml");//map 7
game.addXml("http://mysite.com/images/world2.xml");//map 8
game.addXml("http://mysite.com/images/world3.xml");//map 9
game.addXml("http://mysite.com/images/world13DesertDoubleTrain.xml");//map 10
game.addXml("http://mysite.com/images/world14DoubleTrain.xml");//map 11
game.loadXmlMaps();
clouds = new CloudManager(5);
clouds.minSpeed = 25;
clouds.maxSpeed = 35;
game.addGameChild(clouds);
}
下面是我的 EngineApi() 类中
public function addXml(path:String):void
{
xmlDatas.push(path);
}
public function loadXmlMaps():void
{
var gLoader = new gameLoader();
gLoader.xmlToArray(xmlDatas.shift(),10,100);
gLoader.addEventListener("xmlComplete", FinishXmlMaps);
}
public function FinishXmlMaps(e:Event)
{
if(useTiles)
{
tileEg.mapHolder.push(gameLoader(e.currentTarget).tileArray);
}
if(xmlDatas.length > 0)
{
loadXmlMaps();
}else
{
dispatchEvent(new Event("XMLSCOMPLETE"));
}
}
这是我的 gameLoader 类中的代码
public function xmlToArray(s:String, cols:Number, rows:Number):void
{
this.cols = cols;
this.rows = rows;
//load in tile sheet image
var xmlLoader;
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, xmlLoadComplete);
xmlLoader.load(new URLRequest(s));
}
private function xmlLoadComplete(e:Event):void
{
var mazeData = new XML(e.currentTarget.data) as XML;
//loop through xml and add rows and columns to aTileMap array
for (var rowCtr=0;rowCtr<rows;rowCtr++) {
var tempArray:Array=new Array();
for (var colCtr=0;colCtr<cols;colCtr++) {
tempArray.push(mazeData.tilerow[rowCtr].tilecol[colCtr]);
}
tileArray.push(tempArray);
}
trace("xml done");
dispatchEvent(new Event("xmlComplete"));
}//END XMLLOAD
下面的代码几乎是数据检索 xml 并将其转换为数组的过程。这一切都有效。我刚刚收到错误,因为我猜这是跨域问题。我的问题是我该如何解决它。
I am creating a game that uses tiling and xml files. I am trying to retrieve these files from an outside server. When I run the program in debug mode on my local machine, it works great. But when I upload to a server. I get this error
SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content:
A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
Below is my code
private function init():void
{
game = new EngineApi();
gameObject.eApi = game;
gameObject.EG = this;
game.Tiling(true,800,640,80,80);
game.tileEg.offsY = 7000;
game.tileEg.ScrollLoop(true,0,1,true);//0,1
context.checkPolicyFile = true;
flash.system.Security.loadPolicyFile("http://mysite.com/images/tileSheet.png");
flash.system.Security.loadPolicyFile("http://mysite.com/images/world.xml");//map 0
flash.system.Security.loadPolicyFile("http://mysite.com/images/world1.xml");//map 1
flash.system.Security.loadPolicyFile("http://mysite.com/images/world7.xml");//world 7 and 8 are train track maps. map 2
flash.system.Security.loadPolicyFile("http://mysite.com/images/world8.xml");//map 3
flash.system.Security.loadPolicyFile("http://mysite.com/images/world9.xml");//Ending of 8 //map 4
flash.system.Security.loadPolicyFile("http://mysite.com/images/world10spaceInvader.xml");//Beginning of tracks being centered //map 5
flash.system.Security.loadPolicyFile("http://mysite.com/images/world11LoopBoss.xml");//Tracks loop (you fight boss) //map 6
flash.system.Security.loadPolicyFile("http://mysite.com/images/world12toDesert.xml");//map 7
flash.system.Security.loadPolicyFile("http://mysite.com/images/world2.xml");//map 8
flash.system.Security.loadPolicyFile("http://mysite.com/images/world3.xml");//map 9
flash.system.Security.loadPolicyFile("http://mysite.com/images/world13DesertDoubleTrain.xml");//map 10
flash.system.Security.loadPolicyFile("http://mysite.com/images/world14DoubleTrain.xml");//map 11
game.AddTileSheet("http://mysite.com/images/tileSheet.png");
game.tw = 80;
game.th = 80;
game.LoadTileSheets();
game.addEventListener("tileLoadComplete", prePareTiles);
//anything labeled with map (i.e. map 1) is the order of how the game see's it
game.addXml("http://mysite.com/images/world.xml");//map 0
game.addXml("http://mysite.com/images/world1.xml");//map 1
game.addXml("http://mysite.com/images/world7.xml");//world 7 and 8 are train track maps. map 2
game.addXml("http://mysite.com/images/world8.xml");//map 3
game.addXml("http://mysite.com/images/world9.xml");//Ending of 8 //map 4
game.addXml("http://mysite.com/images/world10spaceInvader.xml");//Beginning of tracks being centered //map 5
game.addXml("http://mysite.com/images/world11LoopBoss.xml");//Tracks loop (you fight boss) //map 6
game.addXml("http://mysite.com/images/world12toDesert.xml");//map 7
game.addXml("http://mysite.com/images/world2.xml");//map 8
game.addXml("http://mysite.com/images/world3.xml");//map 9
game.addXml("http://mysite.com/images/world13DesertDoubleTrain.xml");//map 10
game.addXml("http://mysite.com/images/world14DoubleTrain.xml");//map 11
game.loadXmlMaps();
clouds = new CloudManager(5);
clouds.minSpeed = 25;
clouds.maxSpeed = 35;
game.addGameChild(clouds);
}
Below is in my EngineApi() class
public function addXml(path:String):void
{
xmlDatas.push(path);
}
public function loadXmlMaps():void
{
var gLoader = new gameLoader();
gLoader.xmlToArray(xmlDatas.shift(),10,100);
gLoader.addEventListener("xmlComplete", FinishXmlMaps);
}
public function FinishXmlMaps(e:Event)
{
if(useTiles)
{
tileEg.mapHolder.push(gameLoader(e.currentTarget).tileArray);
}
if(xmlDatas.length > 0)
{
loadXmlMaps();
}else
{
dispatchEvent(new Event("XMLSCOMPLETE"));
}
}
And this is the code in my gameLoader class
public function xmlToArray(s:String, cols:Number, rows:Number):void
{
this.cols = cols;
this.rows = rows;
//load in tile sheet image
var xmlLoader;
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, xmlLoadComplete);
xmlLoader.load(new URLRequest(s));
}
private function xmlLoadComplete(e:Event):void
{
var mazeData = new XML(e.currentTarget.data) as XML;
//loop through xml and add rows and columns to aTileMap array
for (var rowCtr=0;rowCtr<rows;rowCtr++) {
var tempArray:Array=new Array();
for (var colCtr=0;colCtr<cols;colCtr++) {
tempArray.push(mazeData.tilerow[rowCtr].tilecol[colCtr]);
}
tileArray.push(tempArray);
}
trace("xml done");
dispatchEvent(new Event("xmlComplete"));
}//END XMLLOAD
The code below is pretty much the process the data goes through to retrieve and translate the xml to an array. It all works. I just get an error because I guess its a crossdomain issue. My question is how do I resolve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您似乎以错误的方式使用 Security.loadPolicyFile 函数。它用于读取控制服务器如何允许 Flash Player 从中获取数据的特殊 XML 文件,而不是用于加载图像或其他文件,如 loadPolicyFile("http://mysite.com/images/tileSheet.png") 调用您所拥有的。
以下是 Security.loadPolicyFile 的文档:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/system/Security.html#loadPolicyFile()
以下是有关策略文件的信息:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e6 3e3d118a9b90204-7e08.html
关于如何解决跨域问题,最简单的方法是在服务器的根目录下放置一个crossdomain.xml文件。在其中,您可以指定允许哪些域从服务器获取数据。您可以使用 * 来允许任何域。以下是允许任何域的 crossdomain.xml 示例:
http://api.flickr.com/ crossdomain.xml
Flash Player 将在必要时自动查找该文件,并且您的 ActionScript 代码不需要自行执行任何进一步的操作。
使用 Security.loadPolicyFile() 主要用于需要更多受控和/或细粒度跨域策略的情况。
It seems to me like you are using the Security.loadPolicyFile function in the wrong way. It's for reading special XML files that control how the server allows Flash Player to fetch data from it, not for loading images or other files, like in the loadPolicyFile("http://mysite.com/images/tileSheet.png") call that you have.
Here's the documentation for Security.loadPolicyFile:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/system/Security.html#loadPolicyFile()
And here is info on policy files:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e08.html
Regarding how to resolve crossdomain issues, the easiest way is to put a crossdomain.xml file at the root of the server. In it, you can specify what domains are allowed to fetch data from the server. You can use * for allowing any domain. Here is an example of a crossdomain.xml that allows any domain:
http://api.flickr.com/crossdomain.xml
Flash Player will automatically look for that file, when necessary, and your ActionScript code doesn't need to take any further action on its own.
Using Security.loadPolicyFile() is primarily for situations where there is need for more controlled and/or fine grained crossdomain policies than that.