从另一个域访问 swf

发布于 2024-09-28 20:16:41 字数 2691 浏览 5 评论 0原文

当尝试从与我的 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);
        }
    }
}

When trying to load a swf from a domain different from my swf's domain, I get this error:

*** 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.

Here is my 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"/>

Here is my actionscript code :

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);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没︽人懂的悲伤 2024-10-05 20:16:41
context.securityDomain = SecurityDomain.currentDomain;

我也必须包括上面的行...

事实上,我可以取消 :

 Security.loadPolicyFile("http://mydomain.com/crossdomain.xml");

 context.checkPolicyFile = true;  
context.securityDomain = SecurityDomain.currentDomain;

I had to include the above line too...

And In fact, I could do away with :

 Security.loadPolicyFile("http://mydomain.com/crossdomain.xml");

and

 context.checkPolicyFile = true;  
把回忆走一遍 2024-10-05 20:16:41

尝试从本地 Web 服务器而不是文件系统执行 SWF。
在 Flash Builder 中,转到项目属性并选择 Flex 构建路径。更改输出文件夹和输出文件夹 URL 以匹配 Web 服务器的文档根目录及其相应的 URL。

如果您仍然需要从本地文件系统启动 SWF,请尝试调整 Flash Player 的安全设置并将您的本地目录添加到受信任的目录中。

Try executing your SWF from a local web server instead from the filesystem.
In Flash Builder go to the properties of your project and select Flex Build Path. Change the Output folder and Output folder URL to match your web server's document root and its corresponding URL.

If you still need to start your SWF from the local filesystem try tweaking the Flash Player's security settings and add you local directory to the trusted ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文