Flex 根据图片url获取bitmapdata并绑定到多个Image

private function getImage(url:String):void
{
	var loader:Loader = new Loader();
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void
	{
		//获取已加载图片的url地址;
		var url:String = (e.target.content as Bitmap).loaderInfo.url;
		imgObj[url] = (e.target.content as Bitmap).bitmapData;
	});
	loader.load(new URLRequest(url));
} 

根据url的key取图片bitmapdata
//因为BitmapData是引用类型数据,要绑定多个图片需要用BitmapData的副本,再用Bitmap封装;
var bd:BitmapData = imgObj[url].clone();
img.source = new Bitmap(bd,'auto',true);

参考:
http://www.iteye.com/topic/432410
http://bbs.9ria.com/viewthread.php?tid=3117

你可能感兴趣的:(as3)