[英]Accessing a swf from another domain
嘗試從不同於SWF域的域中加載SWF時,出現以下錯誤:
*** Security Sandbox Violation ***
SecurityDomain 'file:///C:/Documents and Settings/Welcome/My Documents/Flex Builder 3/SwfLoad/bin-debug/SwfLoad.swf' tried to access incompatible context
'http://example.com/crossdomain.xml'
loading of class failed. class name is MGroundTileInsideZ1 failure error is SecurityError:
Error #2119: Security sandbox violation: caller file:///C:/Documents and Settings/Welcome/My Documents/Flex Builder 3/SwfLoad/bin-debug/SwfLoad.swf
cannot access LoaderInfo.applicationDomain owned by http://example.com/zoom_assets/GroundTiles.swf.
這是我的crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
這是我的動作代碼:
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
public class SwfLoad extends Sprite
{
public function SwfLoad()
{
Security.loadPolicyFile("http://example.com/crossdomain.xml");
var loader:Loader = new Loader();
var url:String = "http://example.com/zoom_assets/GroundTiles.swf";
var request:URLRequest = new URLRequest(url);
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.applicationDomain = ApplicationDomain.currentDomain;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
function(e:Event):void {
try {
var className:String = "MGroundTileInsideZ1";
var appDomain:ApplicationDomain = loader.contentLoaderInfo.applicationDomain;
var cl:Class = appDomain.getDefinition(className) as Class;
//var cl:Class = getDefinitionByName(className) as Class;
}
catch (e:Error) {
trace("loading of class failed. class name is " + className + " failure error is " + e);
}
});
loader.load(request,context);
}
}
}
context.securityDomain = SecurityDomain.currentDomain;
我也必須包括上述內容...
實際上,我可以取消:
Security.loadPolicyFile("http://mydomain.com/crossdomain.xml");
和
context.checkPolicyFile = true;
嘗試從本地Web服務器而不是從文件系統執行SWF。 在Flash Builder中,轉到項目的屬性,然后選擇“ Flex Build Path”。 更改輸出文件夾和輸出文件夾URL,以匹配您的Web服務器的文檔根目錄及其對應的URL。
如果仍然需要從本地文件系統啟動SWF,請嘗試調整Flash Player的安全設置,然后將本地目錄添加到受信任的目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.