SecurityError: Error #2123: 安全沙箱冲突,对NetStream使用BitmapData.draw()时出现的

来源:互联网 发布:软件版本更新说明文档 编辑:程序博客网 时间:2024/05/19 03:46

    本来就刚接触AS3/Flash这玩意儿,又遇到马上要用Flash Media Server做东西,更要命的是这两天被一个名为“SecurityError: Error #2123: 安全沙箱冲突”,被折腾好久。

    网上对安全沙漏问题普遍的办法就是:

    1.在HTTP服务器上放一个crossdomain.xml文件

    2.修改FMS下的main.asc代码

    第一种方法是用HTTP服务器时候的可行方法[1],第二种方法是使用FMS时遇到该问题的解决方法。

 

    我使用的是FMS4,要使用vod,在安装目录下的application下边的vod文件夹下边,以main.far进行修改就行了。main.far是一个打包的文件,可以用winrar解包[2],里面有Application.xml和main.asc两个文件。对main.asc进行修改即可。

    打开main.asc文件,找到application.onConnect函数。其中有两行

p_client.audioSampleAccess = "/";p_client.videoSampleAccess = "/";

    它们原本是被注释掉的,把注释去除就可以了。其实程序中已经有注释说明:

    As default, all clients are disabled to access raw audio and video and data bytes in a stream through the use of BitmapData.draw() and SoundMixer.computeSpectrum()., Please refer Stream Data Access doccumentations to know flash player version requirement to support this restriction. Access permissions can be allowed for all by uncommenting the following statements

    改完后,将Application.xml和main.asc两个文件重新进行打包打为main.far。使用的是FMS自带的在安装目录下的tools文件夹下的far.exe[3]。打包这两个文件只需在命令行下用下列命令即可:

    far -package -archive main.far -files main.asc Application.xml

    运行后,会在far.exe目录下生成main.far,复制到之前的vod目录下即可。

   

    于是完毕,现在就可以使用NetStream的raw数据啦。

    但是我运行程序,依然提示安全沙漏!这是怎么回事呢?原来是我在数据还没有缓冲好时就迫不急待使用draw函数来获取NetStream的数据了[4]

    解决办法就是使用NetStatusEvent.NET_STATUS事件,当其为NetStream.Buffer.Full状态时,我们再对NetStream的数据进行访问。这时就不会出现安全沙漏了。

 

 

参考:

[1]HTML Developer’s Guide for Adobe AIR: Accessing loaded media as datahttp://help.adobe.com/en_US/air/html/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d1b.html

[2]FMS main.far是什么文件,如何修改 http://blog.sina.com.cn/s/blog_45914ace0101730m.html

[3]FMS3中的实用工具(1)——far.exe http://hi.baidu.com/sgfswen/item/1bc0444518a12238fa8960a3

[4]Client.videoSampleAccess False-Negativehttp://inflagrantedelicto.memoryspiral.com/2008/06/clientvideosampleaccess-false-negative/comment-page-1/#comment-21417


原创粉丝点击