AS3安全沙箱冲突 [英] as3 Security Sandbox Violation

查看:952
本文介绍了AS3安全沙箱冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过所有类似的话题已经没有运气,所以我张贴有关此错误的一个新问题。

I've read all similar topics already with no luck, so I'm posting a new question about this error.

我想用这个code加载从另一个SWF文件中的SWF文件:

I am trying to load a swf file from another swf file using this code:

var loader:Loader = new Loader()

//listen for loading progress
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//listen for when the load is finished
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoaderError);

//load!
var rr:URLRequest = new URLRequest("http://localhost/Gen-Tree.swf")
loader.load(rr);


function onLoaderError(event:SecurityErrorEvent) {
    trace("hi")
}

function onProgress(event:ProgressEvent):void
{
    //calculate how much has been loaded
    var percentageLoader:Number = event.bytesLoaded / event.bytesTotal;

    //use your percentage number here to drive a loader bar graphic
}

function onComplete(event:Event):void
{
    //remove listeners now that loading is done
    loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);

    //add loaded swf to the stage
    addChild(loader.content);

}

和我得到一个错误信息如下:

and I get an error messages as follows:

SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'

任何想法?

推荐答案

您正在尝试加载外部SWF关闭文件系统,这将引发安全错误。把它放在一台服务器上,它应该正常工作,只要两个主权财富基金都在同一个域。或者运行一个本地服务器和尝试这一点。

You're trying to load the external swf off of the file system, which will throw security errors. Put it up on a server, and it should work fine, as long as both swfs are on the same domain. Or run a local server and try it on that.

如果这两个主权财富基金不是在同一个域中,你需要添加一个的crossdomain.xml 。它会去服务器上的根,它会是这个样子:

If the two swfs aren't in the same domain, you'll need to add a crossdomain.xml. It'll go on the server root and it'll look something like this:

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

除非你不应该只使用 * ,因为它会打开你到安全风险。你要特别白名单中的其他领域。您可以了解更多有关跨域策略文件这里

Except you shouldn't just use * as it'll open you up to security risks. You'll want to specifically white-list the other domain. You can learn more about cross domain policy files here.

更新:
此外,由于装载器SWF正在访问正在加载的内容(通过 loader.content ),您将需要安全权限添加到内容SWF(看起来是名为根Tress.swf ):

UPDATE:
Additionally, since the loader swf is accessing the content it is loading (through loader.content), you'll need to add security permissions to that content swf (looks like it is called Gen-Tress.swf):

import flash.system.Security;

Security.allowDomain("*");

另外值得一提的是,装载机的DisplayObject ,这意味着你可以直接将其添加到的addChild(装载机)而不是的addChild(loader.content) 。如果不访问装载机的内容,通常可以避开安全沙箱冲突的错误,而不是要处理,允许域和跨域策略。

It's also worth noting that Loader is a DisplayObject, meaning you can directly add it to the stage with addChild(loader) instead of addChild(loader.content). By not accessing the Loader's content, you can usually avoid security sandbox violation errors and not have to deal with allowing domains and cross domain policies.

这篇关于AS3安全沙箱冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆