tishi_mc.visible = false;
var temp_domain:String = stage.loaderInfo.parameters.my_domain;
var inid:String = stage.loaderInfo.parameters.inid; //最大上传文件　多少Ｍ
var max_up_kb:int = stage.loaderInfo.parameters.max_up_kb; //最大上传文件　多少k
var max_up_M:String = stage.loaderInfo.parameters.max_up_M; //最大上传文件　多少Ｍ
var active:String = stage.loaderInfo.parameters.active; //有效性
var up_i:uint = 0; //开始数
var up_num:uint = 0; //总数
//max_up_kb=102400000;

if(temp_domain == null){temp_domain = "http://localhost/bao/admin/system/"; }
var my_domain:String = temp_domain + "";

//点击 “上传文件”---------------------------------------------------------------------------------------------------------
//trace(inid)
var imageTypes:FileFilter = new FileFilter("图片文件 *.jpg","*.jpg");
var allTypes:Array = new Array(imageTypes);
var file:FileReference;
var fileRef:FileReferenceList = new FileReferenceList();

btn_upload.addEventListener(MouseEvent.CLICK, btn_upload_click);
function btn_upload_click(event:MouseEvent)
{
	
    fileRef.addEventListener(Event.SELECT, selectHandler);
    fileRef.browse(allTypes);
	
	function selectHandler(event:Event):void 
	{
		trace("selectHandler: " + fileRef.fileList.length + " files");
		up_num = fileRef.fileList.length;
		upload_pic();
    }
 
}

   
function upload_pic()
{
	trace(up_i,fileRef.fileList.length)
	if (up_i < fileRef.fileList.length)
	{	
		
			ExternalInterface.call('up_start()');
            file = FileReference(fileRef.fileList[up_i]);
			if (file.size > max_up_kb )
			{
			
				tishi_mc.visible = false; 
				ExternalInterface.call('alert("抱歉！您选择的文件太大，不能超过'+max_up_M+'M 请重新选择，或者通过软件调整该文件的大小。")'); 
			}
			else
			{	
				//trace(file.name)
				tishi_mc.visible = false; 
				var UTIME:String = new Date().getTime().toString()+new Date().getHours().toString();
				var params:URLVariables = new URLVariables();
				params.ptype = file.type;
				params.pname = UTIME;
				var request:URLRequest = new URLRequest(my_domain+"up_pic.php?inid="+inid+"&active="+active+"&time="+new Date())
				request.method = URLRequestMethod.POST;
				request.data = params;
				
				file.addEventListener(Event.COMPLETE, completeHandler);
				file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
				file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
				file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
				file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
				file.upload(request);
				tishi_mc.note.text = "上传图片"+(up_i+1)+"，请不要离开此页面。";
				function uploadCompleteDataHandler(event:DataEvent):void
				{					
					var return_list:String = event.data;
					var return_data:Array = return_list.split("||"); // 0 $pass.'|1|'.$return_url.
					trace(return_list);
					up_i++;
					if (up_i == fileRef.fileList.length)
					{
						tishi_mc.note.text = "上传完毕。";
						ExternalInterface.call('up_end()');
					}
					else
					{
						upload_pic();
					}
				}
				function completeHandler(event:Event):void 
				{
					var file:FileReference = FileReference(event.target);
					trace("completeHandler: name=" + file.name);
				}
				function ioErrorHandler(event:Event):void
				{
					tishi_mc.visible = false;
					ExternalInterface.call('alert("上传中出现错误,请重新操作")'); 
				}	
				function securityErrorHandler(event:Event):void 
				{
					tishi_mc.visible = false;
					ExternalInterface.call('alert("上传中出现错误,请重新操作")');
				}
				 function progressHandler(event:ProgressEvent):void 
				{
					var file:FileReference = FileReference(event.target);
					tishi_mc.visible = true; //显示上传提示
					var loadpre:int=event.bytesLoaded/event.bytesTotal*100;
					tishi_mc.jin_du_mc.scaleX=loadpre;
					tishi_mc.jin_du_txt.text = loadpre + "%。";	
					if(loadpre==100){tishi_mc.note.text = "正在处理图片"+(up_i+1)+"请稍等..";}
				}		

				
			}
		
	}
}