有可能赶上&在远程swf中编辑swf加载?

时间:2011-07-04 17:01:53

标签: flash actionscript-3

由于我在这里遇到沙盒的一些问题,我正在寻找一个可以用来代理远程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 ..任何建议?

1 个答案:

答案 0 :(得分:0)

看起来你正在尝试使用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添加侦听器,以防万一出错(文件丢失,网址错误等)