替代为的BitmapData.draw错误错误、BitmapData、draw

2023-09-08 14:16:20 作者:爱情来临就像黑夜失去本性

我收到

引发SecurityError:错误#2123:安全沙箱冲突:   的BitmapData.draw:文件:///Users/.../project/bin-debug/Project.swf   不能访问设rtmp://flash.project.com/project/。没有政策文件   授予访问权限。

SecurityError: Error #2123: Security sandbox violation: BitmapData.draw: file:///Users/.../project/bin-debug/Project.swf cannot access rtmp://flash.project.com/project/. No policy files granted access.

这发生在这一行:

temporaryBitmap = new BitmapData(FlexGlobals.topLevelApplication.stage.width, FlexGlobals.topLevelApplication.stage.height, false);
temporaryBitmap.draw(DisplayObject(FlexGlobals.topLevelApplication.stage)); // this line

有没有办法来解决这个错误?从研究我做这似乎是相关的RTMP流的权限。如果是这样的话,那么它的确定不显示流,因为我只是想找到容器的尺寸。因此,如果有一种方式来获得应用程序的快照,并显示一个黑盒子,其中视频流,这很好,以及。

Is there a way to get around this error? From research I've done it appears to be related to the RTMP stream permissions. If that's the case then it's ok to not display the stream since I am only trying to find the dimensions of the container. So if there was a way to get a snapshot of the application, and show a black box where the video stream is, that's fine as well.

我创建了一个开发通用的工具,所以我不知道什么样的内容会或无法使用的时间提前。我要处理这两种情况。我能想象我会从不同的域加载图像时,也应对这一问题。

I'm creating a generic tool for developers so I won't know what content will or will not be available ahead of time. I have to handle both situations. I can imagine I will have to deal with this issue when loading images from different domains as well.

推荐答案

我找不到任何其他的解决办法来告诉它是否会出错或不那么我包的呼叫,像这样一个try catch块:

I couldn't find any other solution to tell if it would error or not so I wrapped the call in a try catch block like so:

try {
    drawBitmapData(temporaryBitmap, DisplayObject(FlexGlobals.topLevelApplication));
}
catch (e:Error) {
    // could not draw so don't draw
}

// continue 

我不得不把电话拉进一个单独调用它不抛出错误,而是跳到了code下一节:

I had to put the call to draw into a separate call for it to not to throw the error but rather skip to the next section of code:

public function drawBitmapData(bitmapData:BitmapData, displayObject:DisplayObject, matrix:Matrix = null):void {
    bitmapData.draw(displayObject, matrix);
}