as3跨域加载外部图片
2009-06-30 16:39
281 查看
跨域加载外部图片除需要设置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 );
}
}
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:加载外部图片到界面
- AS3加载图片等外部资源
- AS3 使用Loader对象加载外部图片
- AS3:加载外部图片到界面
- AS3跨域读取图片文件报错需要一个策略文件,但在加载此媒体时未设置 checkPolicyFile 标志
- flash加载外部图片等比缩放类(as3)
- as3加载外部图片的方法详解
- as3动态加载多张图片,自动缩放并加鼠标边框![新手]
- flash加载外部图片进度显示
- as3加载外部XML文件
- as3 调用外部资源文件(swf文件、图片文件)
- Flash8帮助中一个加载外部图片的例子(有进度条)
- AS3 Starling 塔防教程——第一部分——外部文件加载
- 绕开AS3安全沙箱,跨域加载SWF
- 动态加载并复制外部图片
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
- as3加载图片
- 通过XMLHttpRequest加载外部图片文件或数据