2010-02-07 66 views
0

我創建一個使用瓷磚和XML文件的遊戲。我試圖從外部服務器檢索這些文件。當我在本地機器上以調試模式運行程序時,它工作得很好。但是當我上傳到服務器。我得到這個錯誤的SecurityError:錯誤#2122:安全沙箱衝突:LoaderInfo.content:

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轉換爲數組的過程。這一切都有效。我只是得到一個錯誤,因爲我猜想它是一個跨域問題。我的問題是我如何解決它。

回答

3

它就像你正在使用錯誤的方法調用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/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e08.html

關於如何解決跨域問題,最簡單的方法是把一個crossdomain.xml文件放在服務器的根目錄下。其中,您可以指定允許哪些域從服務器獲取數據。您可以使用*來允許任何域。這裏是允許任何域的crossdomain.xml的例子:

http://api.flickr.com/crossdomain.xml

Flash Player將自動查找該文件,在必要的時候,你的ActionScript代碼不需要採取任何進一步的行動了擁有。

使用對Security.loadPolicyFile()主要用於哪裏有需要更多的控制和/或細粒度跨域比政策的情況。

+0

這整個政策文件仍然是相當混亂給我,但閱讀鏈接後,你給現在我可以看到,爲什麼你的答案顯得更加撲朔迷離......所以,我感覺compeled要麼在這裏或大量添加其他的答案編輯你的。你說什麼? – cregox 2011-07-06 09:44:48

+0

請添加另一個答案。 – 2011-07-06 10:15:38

相關問題