AIR加载服务器承载的SWF到同一个沙箱 [英] AIR Loading server hosted swf into same sandbox

查看:112
本文介绍了AIR加载服务器承载的SWF到同一个沙箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AIR应用程序我的工作,需要加载SWF(总是从本地主机)将访问一些方法,它的父,反之亦然。我并不关心,虽然在桌面应用程序打开巨大的安全漏洞。我一直在寻找全国各地,但不断撞击墙壁,每个执行那里。

我在SWF当前设置负载和它扮演,但我从沙箱中的小错误,因为我不是在同一个作为应用​​程序。有谁知道如何让过去这个错误所以完全自由打开了AIR应用程序与SWF之间?

*安全沙箱冲突*

SecurityDomain中HTTP://localhost/test.swf尝试访问不兼容的情况下的应用程序:/Test_Player.swf

 公共职能loadSWF():无效{

// VAR方面:的LoaderContext =新的LoaderContext();
//context.checkPolicyFile = TRUE;
//context.applicationDomain = ApplicationDomain.currentDomain来;
//context.securityDomain = SecurityDomain.currentDomain的;

VAR REQ:的URLRequest =新的URLRequest(swfURL);
adLoader =新的Loader();

videoCanvas.rawChildren.addChild(adLoader);

loader.contentLoaderInfo.addEventListener(Event.INIT,adLoadedHandler,假,0,真正的);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioError在,假,0,真正的);

//loader.load(req,背景);
loader.load(REQ);
}
 

解决方案

您需要加载你遥远的SWF与URLLoader和再通过loadByte重新装入。通过这种方法,你会被传递的安全性。

 包
{
    进口flash.display.Loader;
    进口flash.display.Sprite;
    进口对象类型:flash.events.Event;
    进口flash.net.URLLoader;
    进口flash.net.URLLoaderDataFormat;
    进口flash.net.URLRequest;
    进口flash.system.ApplicationDomain;
    进口flash.system.LoaderContext;

    公共类TestDistantSwf扩展Sprite
    {
        私人VAR _urlLoader:的URLLoader =新的URLLoader;
        私人VAR _loader:装载机=新的Loader;

        公共职能TestDistantSwf()
        {

            的addChild(_loader);
            //将无法正常工作
            //_loader.load(new的URLRequest(HTTP://localhost/test.swf));

            //将它作为二进制
            _urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            _urlLoader.addEventListener(引发Event.COMPLETE,的onLoad);
            _urlLoader.load(新的URLRequest(HTTP://localhost/test.swf));
        }

        私有函数的onLoad(五:事件):无效
        {
            //加载遥远的SWF本地数据
            _loader.loadBytes(_urlLoader.data,新的LoaderContext(假,ApplicationDomain.currentDomain来));
        }
    }
}
 

如果你需要通过像闪光变种参数,双向做到这一点,如果使用AIR 2.6或更高版本,可以使用LoaderContext.parameters:

 私有函数的onLoad(五:事件):无效
{
    变种LC:的LoaderContext =的新LoaderContext(假,ApplicationDomain.currentDomain来);
    lc.parameters = {
        富:你好!
    };
    lc.allow codeImport = TRUE;

    //加载遥远的SWF本地数据
    _loader.loadBytes(_urlLoader.data,LC);
}
 

然后把它用在你加载的SWF loaderInfo.parameters。

您也可以拨打加载的SWF的函数:

 私有函数onLoadBinary(五:事件):无效
{
    e.target.content.init(你好2!);
}

私有函数的onLoad(五:事件):无效
{
    变种LC:的LoaderContext =的新LoaderContext(假,ApplicationDomain.currentDomain来);
    lc.allow codeImport = TRUE;

    //加载遥远的SWF本地数据
    _loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,onLoadBinary);
    _loader.loadBytes(_urlLoader.data,LC);
}
 

这将加载的SWF在其主类调用:

 公共职能的init(FOO:字符串):无效
{
    跟踪(富);
}
 

I have an AIR App I'm working on and need to load a swf(always from localhost) which will access some methods in it's parent and vice versa. I'm not concerned with opening gaping security holes in a desktop app though. I've been searching all over but keep hitting walls with each implementation out there.

My current setup loads in the swf and it plays but I get a small error from the sandbox since I'm not in the same one as the app. Does anyone know how to get past this error so there is complete freedom opened up between the AIR app and the swf?

* Security Sandbox Violation *

SecurityDomain 'http://localhost/test.swf' tried to access incompatible context 'app:/Test_Player.swf'

public function loadSWF():void {

//var context:LoaderContext = new LoaderContext();
//context.checkPolicyFile = true;
//context.applicationDomain = ApplicationDomain.currentDomain;
//context.securityDomain = SecurityDomain.currentDomain;

var req:URLRequest = new URLRequest(swfURL);
adLoader = new Loader();

videoCanvas.rawChildren.addChild(adLoader);

loader.contentLoaderInfo.addEventListener(Event.INIT, adLoadedHandler, false, 0, true);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError, false, 0, true);

//loader.load(req, context);
loader.load(req);
}

解决方案

You need to load your distant SWF with an UrlLoader and then reload it through loadByte. With this method you will by pass security.

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;

    public class TestDistantSwf extends Sprite
    {
        private var _urlLoader : URLLoader = new URLLoader;
        private var _loader : Loader = new Loader;

        public function TestDistantSwf()
        {

            addChild(_loader);
            // Won't work
            //_loader.load(new URLRequest("http://localhost/test.swf"));

            // Load it as binary
            _urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            _urlLoader.addEventListener(Event.COMPLETE, onLoad);
            _urlLoader.load(new URLRequest("http://localhost/test.swf"));
        }

        private function onLoad(e : Event) : void
        {
            // Load distant swf data locally
            _loader.loadBytes(_urlLoader.data, new LoaderContext(false, ApplicationDomain.currentDomain));
        }
    }
}

If you need to pass arguments like flash var, two way to do it, if use Air 2.6 or later, you can use LoaderContext.parameters :

private function onLoad(e : Event) : void
{
    var lc : LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    lc.parameters ={
        foo:"hello !"
    };
    lc.allowCodeImport = true;

    // Load distant swf data locally
    _loader.loadBytes(_urlLoader.data, lc);
}

And then get it with loaderInfo.parameters in your loaded SWF.

Or you can call a function of loaded Swf :

private function onLoadBinary(e : Event) : void
{
    e.target.content.init("hello 2 !");
}

private function onLoad(e : Event) : void
{
    var lc : LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
    lc.allowCodeImport = true;

    // Load distant swf data locally
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadBinary);
    _loader.loadBytes(_urlLoader.data, lc);
}

This will call from loaded swf in its main class:

public function init(foo : String) : void
{
    trace(foo);
}

这篇关于AIR加载服务器承载的SWF到同一个沙箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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