开发者

SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content:

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

pr开发者_Python百科ivate 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜