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

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);
相关文章
相关标签/搜索