package classes.matuto.utils.model
{
	
	
	import classes.adobe.images.JPGEncoder;
	import classes.adobe.images.PNGEncoder;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.text.TextField;
	import flash.utils.ByteArray;
	import flash.utils.setTimeout;
	
	
	public class SaveImg extends Sprite
	{
		
		private static var onComplete:Function;
		
		public function SaveImg()
		{
			
		}
		
		public static function load(url:String,complete:Function,bitmapData:BitmapData,type:String="PNG"):void 
		{			
			onComplete								= complete;
			
			var bt 	: ByteArray;
			var JPG	: JPGEncoder = new JPGEncoder(70);
			
			if(type=="PNG")
				bt  								= PNGEncoder.encode(bitmapData);
			else
				bt									= JPG.encode(bitmapData);
			
			var req	: URLRequest 					= new URLRequest(url);
			var ld 	: URLLoader 					= new URLLoader();
			
			ld.addEventListener(Event.COMPLETE, completeLoad);
			
			req.contentType 						= "application/octet-stream";
			req.method 								= URLRequestMethod.POST;
			req.data 								= bt;
			
			ld.load(req);	
		}
		
		private static function completeLoad(e:Event):void 
		{
			onComplete();
		}
		
		
		
	}//end class
	
	
}