加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flash AS3在尝试获取外部swf时获取安全沙箱冲突

发布时间:2020-12-15 07:29:08 所属栏目:百科 来源:网络整理
导读:HII, 我想从另一台服务器加载swf文件到我的flash应用程序. 当我尝试在flash IDE(crl enter)上加载它时一切正常,但是当我将swf作为独立的swf文件运行或通过调试它时,我收到此错误: SecurityError: Error #2121: Security sandbox violation: LoaderInfo.cont
HII,
我想从另一台服务器加载swf文件到我的flash应用程序.
当我尝试在flash IDE(crl enter)上加载它时一切正常,但是当我将swf作为独立的swf文件运行或通过调试它时,我收到此错误:

SecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: file:///C|/Users/something/Desktop/blablabla/myplayer.swf cannot access http://www.somedomain.com/blablabla/lalalala/abc.swf. This may be worked around by calling Security.allowDomain.
at flash.display::LoaderInfo/get content()
at wallplayer_fla::MainTimeline/swfLoaded()[wallplayer_fla.MainTimeline::frame1:216]
Cannot display source code at this location.

我在服务器的根目录中有crossdomain.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" />
</cross-domain-policy>

在“myplayer.swf”中我有:

Security.allowDomain("*");
Security.allowInsecureDomain("*");
...
...
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.checkPolicyFile = true;
loaderContext.allowCodeImport = true;

ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,swfLoaded);
ldr.load(new URLRequest(graySwfFilename),loaderContext);
...
...
var mcExt;
var ldr:Loader;
function swfLoaded(e:Event):void {
    mcExt = MovieClip(ldr.contentLoaderInfo.content);
    ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfLoaded);
    mcExt.x = 0;
    mcExt.y = 0;
    addChild(mcExt);
}

我真的不知道该怎么办……
请帮忙?

解决方法

解决方案:对于Flash 4.x(当前为4.6)和Flash Builder中的AS3:

import flash.system.SecurityDomain;
    import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;
    var loaderContext:LoaderContext = new LoaderContext();
    loaderContext.applicationDomain = ApplicationDomain.currentDomain;
    loaderContext.securityDomain = SecurityDomain.currentDomain; // Sets the security

上下文来解决错误#2121

…现在加载您的SWF

loader.load(new URLRequest(webServerWebURL),loaderContext);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读