flash 导入图片

 
package Src.Tool
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	public class Imager
	{
		private var m_Loader:Loader = null;
		private var m_InitFun:Function = null;
		private var m_szUrl:String = null;
		public var m_Img:Bitmap = null;
		public function Imager(_szUrl:String = null, _funInit:Function = null)
		{
			// constructor code
			m_szUrl = _szUrl;
			m_InitFun = _funInit;
			if (null == m_szUrl)
			{
				var pBD:BitmapData = new BitmapData(800,600,true,0x000000);
				m_Img = new Bitmap(pBD);
				if (null != m_InitFun)
				{
					m_InitFun();
					m_InitFun = null;
				}
			}
			else
			{
				m_Loader = new Loader();
				m_Loader.load(new URLRequest(m_szUrl));
				m_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			}
		}
		private function onComplete(_evt:Event):void
		{
			m_Img = Bitmap(_evt.target.content);
			if (null == m_Img)
			{
				trace("下载" + m_szUrl + "文件失败!");
			}
			m_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
			m_Loader = null;
			if (null != m_InitFun)
			{
				m_InitFun();
				m_InitFun = null;
			}
		}
		public function drawImg(_destImg:BitmapData, _destPos:Point, _srcRect:Rectangle = null)
		{
			if (null != m_Img)
			{
				if (null == _srcRect)
				{
					_srcRect = new Rectangle(0,0,m_Img.bitmapData.width,m_Img.bitmapData.height);
				}
				//var pImg:BitmapData = new BitmapData(rect.width, rect.height, true, 0x000000);
				_destImg.copyPixels(m_Img.bitmapData, _srcRect, _destPos);
			}
		}
	}
}

你可能感兴趣的:(function,String,Flash,null,import,Constructor)