2016-10-13 00:16:48 点击量:9 标签: 收藏本文
在测试加载图片时,出现:SecurityError: Error #2123: 安全沙箱冲突:LoaderInfo.content:h...
跨域加载外部图片除需要设置crossdomain外,还需要在loader.load()方法添加context参数,文档显示context参数为LoaderContext 类:
load(request:URLRequest, context:LoaderContext = null):void
When loading images (JPEG, GIF, or PNG) instead of SWF files, there is no need to specify a SecurityDomain or an application domain, because those concepts are meaningful only for SWF files. Instead, you have only one decision to make: do you need programmatic access to the pixels of the loaded image? If so, see the checkPolicyFile property.
所以,跨域加载正确的写法为:
- import flash.system.LoaderContext;
- var loadc:LoaderContext = new LoaderContext(true);
- var loader:Loader = new Loader();
- var request:URLRequest = new URLRequest(url);
- loader.load(request, loadc);
否则,flash player安全沙箱会报“checkPolicyFile ”错误。
这个疏忽出现在了Papervision3D中。使用BitmapFileMaterial时,如果使用的是跨域图片进行贴图,尽管设置了crossdomain.xml,仍然会报沙箱错误,解决方法是修改loadNextBitmap方法:
- private function loadNextBitmap():void
- {
- // Retrieve next filename in queue
- var file:String = _waitingBitmaps[0];
- var request:URLRequest = new URLRequest( file );
- var lc:LoaderContext = new LoaderContext(true);
- var bitmapLoader:Loader = new Loader();
- bitmapLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadBitmapCompleteHandler );
- try
- {
- // Load bitmap
- bitmapLoader.load( request, lc );
- // Save original url
- _loaderUrls[ bitmapLoader ] = file;
- // Busy loading
- _loadingIdle = false;
- Papervision3D.log( "BitmapFileMaterial: Loading bitmap from " + file );
- }
- catch( error:Error )
- {
- // Remove from queue
- _waitingBitmaps.shift();
- // Loading finished
- _loadingIdle = true;
- Papervision3D.log( "[ERROR] BitmapFileMaterial: Unable to load file " + error.message );
- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室