【问题标题】:Workaround for Security.allowDomainSecurity.allowDomain 的解决方法
【发布时间】:2013-02-08 07:51:31
【问题描述】:

我有一些应该从外部服务器访问的 SWF 文件。为了能够做到这一点,我需要在每个 SWF 文件中都有 Security.allowDomain。这里的问题是我没有这些文件的 FLA,而且有数千个 SWF。

是否有更好的方法将这些文件配置为可从其他域访问? 就像拥有某种配置文件一样。

【问题讨论】:

    标签: actionscript-3 flash apache-flex actionscript flex4


    【解决方案1】:

    是的,有一种解决方法,但我认为这是一个安全漏洞,因此可以在任何版本的 Flash Player 中修复。同时它现在可以工作,所以这里是解决方案 - 使用 URLLoaderBINARY dataFormat 作为 swf 字节的预加载器:

    没有安全权限的swf脚本:

    package
    {
    import flash.display.MovieClip;
    
    
    public class astest extends MovieClip
    {
        public function astest()
        {
        }
    
        public function externalCheck():void
        {
            graphics.beginFill(0xFF0000);
            graphics.drawCircle(100, 100, 100);
        }
    }
    }
    

    要加载前一个 swf 并调用 externalCheck 方法的加载器 swf:

    package
    {
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    
    public class astest2 extends MovieClip
    {
        private var loader:Loader;
        private var urlLoader:URLLoader;
    
        public function astest2()
        {
            init();
        }
    
        //this method works fine
        protected function init():void
        {
            urlLoader = new URLLoader();
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.load(new URLRequest("http://domain_with_your_swfs/astest.swf"));
    
            urlLoader.addEventListener(Event.COMPLETE, function(event:Event):void
            {
                addChild(loader = new Loader());
    
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader);
                loader.loadBytes(urlLoader.data as ByteArray);
            });
        }
    
        //this method will fire SecurityError when calling the 'externalCheck' method
        protected function init2(event:Event = null):void
        {
            addChild(loader = new Loader());
    
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader);
            loader.load(new URLRequest("http://domain_with_your_swfs/astest.swf"));
        }
    
        protected function onLoader(event:Event = null):void
        {
            var swf:Object = loader.content;
            swf.externalCheck();
        }
    
    
    }
    }
    

    不要忘记将crossdomain.xml 文件放在要加载的swf 文件的服务器根目录下,否则URLLoader 将无法加载字节,这是唯一的安全要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多