【问题标题】:Is it possible to catch & edit swf loads in remote swf?是否可以在远程 swf 中捕获和编辑 swf 负载?
【发布时间】:2011-07-04 17:01:53
【问题描述】:

由于我在这里的沙盒存在一些问题,因此我正在寻找一种可以代理远程 swf 加载的资产的小解决方法。

目前在加载远程 swf 并尝试绘制位图后出现以下错误:

Security sandbox violation: BitmapData.draw: http://urlhere cannot access http://remotehost/clothes/bg/bg_10438411_bg.swf. This may be worked around by calling Security.allowDomain.

现在,我想看看是否可以捕获并更改远程 swf 加载的 swf。所以我可以通过 php 文件加载它们,然后将它们加载到 swf 中。基本上是编辑它从中加载 swf 的 URL。有什么建议吗?

【问题讨论】:

  • 你能不能显示一些代码,它会让你的问题更容易理解。
  • 是的,但是我没有实际访问远程 swf 的权限。所以我仍然需要捕捉正在发出的请求并编辑 URL。

标签: flash actionscript-3


【解决方案1】:

您似乎正在尝试使用 BitmapData.draw() 绘制已加载 swf 的快照。 您将需要在服务器上保存您正在加载的 swf 的 crossdomain.xml,或者通过服务器端脚本对其进行代理。

如果你有一个crossdomain.xml,你可以使用LoaderContext 作为Loader 的load() 方法的第二个参数,显式请求跨域检查。 如果不满足安全要求,将发送SecurityErrorEvent。 此外,您应该捕获调用 BitmapData 的 draw() 方法时抛出的 SecurityError 并使用 loaderInfo 的 url 来更改它并使用它,但您认为合适:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
loader.load(new URLRequest('yoursite.com/yourfile.swf'),new LoaderContext(true));

function completeHandler(event:Event):void{
    var clone:BitmapData = new BitmapData(1,1);//create a small bitmap to try and draw into
    try{//draw the contents
        clone.draw(event.target.content);
    }catch(error:SecurityError){//expect security error
        trace('SecurityError while loading',event.target.url,'details\n',error.message);    
    }
}
function securityError(event:SecurityErrorEvent):void{
    trace(event.target.url,event);
}

您还可以为 IOErrorEvent 和 HTTPStatusEvent 添加侦听器,以防万一出现问题(文件丢失、url 错误等)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 2015-02-02
    • 2011-07-29
    • 2010-11-06
    • 2017-11-30
    • 2012-11-22
    相关资源
    最近更新 更多