as3跨域加载图片时设置LoaderContext类
来源:互联网 发布:巫启贤 唱功知乎 编辑:程序博客网 时间:2024/04/19 11:13
跨域加载外部图片除需要设置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 lc:LoaderContext = new LoaderContext(true);
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest(url);
loader.load(request, lc);
否则,flash player安全沙箱会报“checkPolicyFile ”错误。
这个疏忽出现在了Papervision3D中。使用BitmapFileMaterial时,如果使用的是跨域图片进行贴图,尽管设置了crossdomain.xml,仍然会报沙箱错误,解决方法是修改loadNextBitmap方法:
// ___________________________________________________________________ LOAD NEXT BITMAP
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 );
}
}
- AS3跨域加载图片时设置LoaderContext类
- as3跨域加载图片时设置LoaderContext类
- [AS3] LoaderContext 解决跨域加载
- AS3.0 LoaderContext
- as3跨域加载外部图片
- LoaderContext 解决跨域的问题!
- as3 关于加载透明图片
- 关于AS3加载透明图片
- [AS3]Flash AS3 Bulk Loader跨域加载(CrossDomain)
- flash加载外部图片等比缩放类(as3)
- AS3结合XML加载多张图片
- Flash AS3 连续加载外部若干图片
- 两种AS3加载图片的方法
- AS3:加载外部图片到界面
- AS3加载图片等外部资源
- 两种AS3加载图片的方法
- AS3:加载外部图片到界面
- AS3 一个loader加载多张图片
- sap abap 查找增强的程序
- WebGoat学习笔记(五)——CSRF Token By-Pass
- 销售订单增强MV45AFZZ
- 第一次写makefile就悲剧了
- EXCEL函数教程大全
- as3跨域加载图片时设置LoaderContext类
- CSS在html页完全正常,到aspx页显示不正常
- perl 二维数组排序
- 常见的abap面试题目,请大家对照学习
- 使用fedora的问题
- 数据库设计中的14个关键技巧
- 通过命令行安装silverlight4
- JS 获取上传文件大小
- TIMESTEN安装配置指南-中文版