加载外部SWF会导致沙箱违规

时间:2013-02-27 14:47:20

标签: flash debugging actionscript cross-domain actionscript-2

我正在尝试加载外部SWF,以便我可以调试它。我不控制SWF源,但我确实控制它所托管的域。

这是我的代码:

import flash.system.Security;
Security.allowDomain("*");

var swf = ["http://rcnhca.org.uk/wp-content/plugins/assessment-quiz/quiz.swf", "quiz_content/data.swf"]

var loadListener:Object = new Object();
loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
    trace(">> loadListener.onLoadComplete()");
    trace(">> httpStatus: " + httpStatus);
}

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mcLoader.loadClip(swf[0], mc);

然而,这会导致以下许多错误:

SecurityDomain 'http://rcnhca.org.uk/wp-content/plugins/assessment-quiz/quiz.swf' tried to access incompatible context 'file:///G|/Lifelong%20Learning/Active%20work/Sites/rcnhca/wp%2Dcontent/plugins/assessment%2Dquiz/as2debug.swf'

我在我的域的根目录下设置了一个crossdomain.xml文件,如下所示:

<?xml version="1.0" ?>
<cross-domain-policy>
  <allow-access-from domain="*"/>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

(见此处:http://rcnhca.org.uk/crossdomain.xml

当我尝试调试时,SWF加载得非常奇怪 - &gt;列出变量或在调试窗格中打开它会导致整个程序崩溃。

1 个答案:

答案 0 :(得分:0)

您似乎错过了实际加载策略文件的代码(仅仅是因为它还不够):

Security.loadPolicyFile('your_domain/crossdomain.xml');

(对于您正在加载的任何其他域名,我们也会修改您的allowDomain('*');电话,以便在所有工作完成后更加具体,但它是现在很好。)

请确保您在申请开始时这样做 - 多年来我一直有这么多头疼,希望它能为您做好准备!

希望这有帮助。